Wednesday 11 January 2012

Magento: Programmatically Reindex Data

In this post you will learn how to reindex Magento Data Programmatically other way you can also do it manually(System -> Index Management).


Below you will find the Index name and their respective keys which will be require to do the same programmatically:

Index Name Index Key
Product Attributes 1
Product Prices 2
Catalog URL Rewrites 3
Product Flat Data 4
Category Flat Data 5
Category Products 6
Catalog Search index 7
Tag Aggregation Data 8
Stock Status 9

So, if you want to do re indexing of  “Category Products” then follow the below method:-
$process = Mage::getModel('index/process')->load(6);
$process->reindexAll();
Make a loop if you want to do the re indexing of all the entities:-
for ($i = 1; $i <= 9; $i++) {
    $process = Mage::getModel('index/process')->load($i);
    $process->reindexAll();
}

Hope this help!
Njoy!

No comments:

Post a Comment