Magento API: Rebuild Indexes after adding new products

前端 未结 2 1121
执念已碎
执念已碎 2020-12-07 15:57

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

$product = Mage::getModel(\'catalog/product\');
$product->setSku($data[         


        
2条回答
  •  抹茶落季
    2020-12-07 16:51

    You can use such a model in Index module.

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

    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.

    Small Suggestion

    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');
    

提交回复
热议问题