Magento – Magento how to re-index product prices pro-grammatically

magento-1.9price

I am trying to re-index product prices after update in my product price but its not working showing me old price in product list page.I am using this code

$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_price');
$process->reindexAll();

i also tried this one

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

But its not working. I have tried from by this command

php indexer.php –reindex catalog_product_price

Its working fine showing me updated prices.

Best Answer

Create external file test.php in magento root. Please add below code in it.

<?php
include 'app/Mage.php';
Mage::app();

// clear cache
Mage::app()->removeCache('catalog_rules_dirty');

// reindex prices
Mage::getModel('index/process')->load(2)->reindexEverything();
/*
1 = Product Attributes
2 = Product Attributes
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
*/

// Recreate a single index programmatically
Mage::getModel('index/process')->load(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE, 'indexer_code')->reindexEverything();
Related Topic