且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento API:添加新产品后重建索引

更新时间:2023-11-30 10:40:16

你可以在 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');