Reindex Data Programmatically in Magento code / import

  • magento reindex programmatically
  • magento There was a problem with reindexing process
  • magento index management
  • there was a problem with reindexing process product flat data

Sometime you need to run/force reindex from code for your custom Magento module or import script. This article will show how to deal this in best Magento code practice.

You can manually reindex data from System -> Index Management. However, this article is concerned how this can be done through code/programming.

Currently, there are 9 indexes. They are as  under (with their respective key  number):-

 

1.

Product Attributes

2. Product Prices

3. Catalog URL Rewrites

4. Product Flat Data

5. Category Flat Data

6. Category Products

7. Catalog Search index

8. Tag Aggregation Data

9. Stock Status

So, if you want to reindex “Category Products” only then you can do as follows:-

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

Looking for improvement for your Magento Store?
Facebook Connector Extension
Product related article extension
Magento Offer popup on exit extension
Unlimited Slideshow Magento Extension
Light Checkout in One Step Magento Extension

If you want to reindex all data then you can loop through these indices and then reindex them:

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

Hope this helps. Thanks.


Comments Closed