How to reindex prices in Magento programatically

I update prices in magento programmatically. How can I reindexing prices after this update. Now I used SSH command:

php indexer.php --reindex catalog_product_price
Chris Stewart Asked on November 26, 2015 in Magento.
Add Comment
1 Answer(s)
Best answer

The following will reindex all of the  indexes available on your Magento.

for ($i = 1; $i <= 9; $i++) {
    $process = Mage::getModel('index/process')->load($i);
    $process->reindexAll();
}

You can also use the Magento collection model to load each index rather than hard coding the ID  in a loop.

/* @var $indexCollection Mage_Index_Model_Resource_Process_Collection */
$indexCollection = Mage::getModel('index/process')->getCollection();
foreach ($indexCollection as $index) {
    /* @var $index Mage_Index_Model_Process */
    $index->reindexAll();
}

Or if you want to reindex just the price one ID, for example ID 2

$process = Mage::getModel('index/process')->load(2);
$process->reindexAll();

You could also call the function getProcessByCode as follows:

$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_price');
$process->reindexAll();
Chris Stewart Answered on November 26, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.