I have written a cron that updates the inventory of my products every night. What indexes need to be reindexed for products to display correctly after stock is changed via script? Does cache need to be refreshed? Trying to pinpoint the exact issue of why "add to cart" was missing from products last week. Reindexing solved that issue last week but need to know if my stock script caused the need to reindex.

up vote 13 down vote accepted

If you update stock options of products you can reindex "Stock Status" tables programmatically:

    try {
        $indexer = Mage::getModel('index/indexer')->getProcessByCode('cataloginventory_stock');
        $indexer->reindexEverything();
    } catch (Exception $e) {
        //Some error handling
    }

To get indexer model use Mage::getModel('index/indexer')->getProcessByCode('some_indexer_code_given_below'). Magento provides several indexers. If you update product by programmatically you can use following indexers, just I give indexer_code and you should change given snippet (see index_process table):

  • catalog_product_attribute - Product Attributes (If you updated attributes which are used layered navigation)
  • catalog_product_price - Product Prices (If you updated prices)
  • catalog_url - Catalog URL Rewrites (If you updated Product or Catalag url)
  • catalog_product_flat - Product Flat Data (If your store uses Flate tables and if you updated product attributes which are used frontend logic wherever)
  • catalog_category_flat - Category Flat Data (If you updated category attributes)
  • catalog_category_product - Category Products (If you addedd or removed products from catalog)
  • catalogsearch_fulltext - Catalog Search Index (If you updated searcheable attributes of product)
  • cataloginventory_stock - Stock Status (If you updated stock options of product)
  • tag_summary - Tag Aggregation Data (If you updated Product tag)

And you can (you should refresh cashes after any updation of products/categories) clean magento cache programmatically in your logic:

Mage::app()->getCacheInstance()->flush();
Mage::app()->cleanCache();

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.