Magento API:添加新产品后重建索引 [英] Magento API: Rebuild Indexes after adding new products

查看:28
本文介绍了Magento API:添加新产品后重建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个脚本,可以让我在 magento 中导入多个产品.

I am currently writing a script that lets me import multiple products in magento.

$product = Mage::getModel('catalog/product');
$product->setSku($data['sku']);
//etc etc
$product->save();

产品创建得很完美,但它不会出现在我的前端,除非我将它保存在后端(不做任何更改!)或者我在后端重建索引.

The product gets created perfectly but it won't show up in my frontend until I either save it in the backend (without changing anything!) OR I rebuild the indexes in the backend.

我对相关数据库表进行了比较,以查看当我保存产品并将这些字段添加到我的导入脚本时发生了什么变化,但它没有任何影响.导入的产品必须没问题,因为它会在我通过后端手动重建索引时显示出来.

I did a diff on the relevant database tables to see what's changing when I save the product and added those fields to my import script, but it did not have any effect. The imported product has to be OK since it shows up when I rebuild the indexes via the backend manually.

缓存被完全禁用.

现在我的问题是:如何在导入我的产品后重建索引?

Now my question is: How can I rebuild the indexes after importing my products?

推荐答案

你可以在 Index 模块中使用这样的模型.

You can use such a model in Index module.

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('reindexAll');

由于您需要重建所有索引,因此没有过滤器应用于集合.但是您可以通过 addFieldToFilter($field, $condition) 方法按参数集(代码、上次重新索引的时间等)过滤索引进程列表.

Since you need to rebuild all the indexes, there is no filters aplied to collection. But you can filter index processes list by set of parameters (code, last time re-indexed, etc) via addFieldToFilter($field, $condition) method.

小建议

在导入产品时将索引设置为手动模式会很棒,这将帮助您加快导入过程,因为其中一些会观察产品保存事件,因此需要一些时间.您可以通过以下方式进行:

Would be great to set indexes to manual mode while you importing the products, it will help you to speed up the import process, because some of them observe product saving event , so it takes some time. You can do it in the following way:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');
// Here goes your
// Importing process
// ................
$processes->walk('reindexAll');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

这篇关于Magento API:添加新产品后重建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆