1

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.

6
  • What does $reindex contain? Are you sure it is loaded? Dec 7, 2016 at 14:43
  • yeah 2 is the id of this process catalog_product_price
    – OBAID
    Dec 7, 2016 at 14:58
  • I know, but I asked it you are sure $reindex is a loaded object or not. Try echoing echo $reindex->getStatus() and see it if works. Dec 7, 2016 at 15:01
  • string(7) "pending" getting this
    – OBAID
    Dec 7, 2016 at 15:07
  • Have you tried running $reindex->reindexEverything() ? Dec 7, 2016 at 15:09

3 Answers 3

1

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();
1

The right function to call is:

Mage::getResourceModel('catalog/product_indexer_price')->reindexProductIds($ids);

Just add it in an observer.

-1

You could build a custom script to run * * * * * /usr/bin/php /path/to/indexer.php --reindex catalog_product_price as a crontab (if you're using Linux).

It's not a magento solution, but it would work if it's something that's mission critical. Where you could have it run on a regular interval? Not the best solution, but it might be what you're looking for.

2
  • The OP wants to do it programmatically, not using the command line. Dec 8, 2016 at 8:00
  • How is that not programmatically? Dec 8, 2016 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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