Sunday, March 22, 2015

Magento programatically refresh reindexing indexes

I have written a script to update the product description information programatically. However, after I run the script, the URL is reset to a empty blank value. Refresh the indexes will re-generate the URL keys.

<?php
### Magento programatically refresh reindexing indexes

function refreshAllIndexes() {
  /* @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();

    #echo '<pre>' . print_r($index->debug(), TRUE) . '</pre>';
  }
}

/**
 * catalog_product_attribute     Product Attributes
 * catalog_product_price         Product Prices
 * catalog_url                   Catalog URL Rewrites
 * catalog_product_flat          Product Flat Data
 * catalog_category_flat         Category Flat Data
 * catalog_category_product      Category Products
 * catalogsearch_fulltext        Catalog Search Index
 * cataloginventory_stock        Stock Status
 * tag_summary                   Tag Aggregation Data
 * targetrule                    Target Rules
 */
function refreshIndex($indexName) {
  $process = Mage::getModel('index/indexer')->getProcessByCode($indexName);
  $process->reindexAll();
}
?>

Reference:

http://www.kennydeckers.com/magento-programatically-reindexing-indexes/

No comments: