Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAGENTO: Reindexing price programmatically

I update prices in magento programmatically. How can I reindexing prices after this update. Now I used SSH command:

php indexer.php --reindex catalog_product_price
like image 849
dido Avatar asked Feb 12 '13 08:02

dido


People also ask

How do I reindex in Magento 2 programmatically?

Here is how to do it. $indexidarray = $this->indexFactory->create()->load($indexid); //If you want reindex all use this code. That's it!

How do I reindex in Magento 2 command line?

Reindexing via Magento 2 Admin Log in to Magento 2 Admin and navigate to System → Index Management. You will see the panel above. Select indexers, which has status Reindex Required, then select in Actions menu Update on Schedule. Press Submit button to apply selected mode to indexers.

What is indexer reindex Magento 2?

Index is how Magento re-constructs these data to optimize the performance of the storefront. Magento is built on a sophisticated architecture which stores merchant data such as prices, users, catalog data in different database tables. When the data changes, the transformed data must be updated or reindexed.

What is Magento indexing?

Indexing is how Magento transforms data such as products and categories, to improve the performance of your storefront. As data changes, the transformed data must be updated or reindexed.


2 Answers

The following will reindex each index.

for ($i = 1; $i <= 9; $i++) {
    $process = Mage::getModel('index/process')->load($i);
    $process->reindexAll();
}

You can also use the Magento collection model to load each index rather than hard coding the id in the for loop.

/* @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();
}

But if you want to reindex just the price the id is 2

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

You could also call the function getProcessByCode as follows:

$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_price');
$process->reindexAll();
like image 148
dmanners Avatar answered Sep 21 '22 08:09

dmanners


By using following SSH command you can reindex all the indexes.

php shell/indexer.php reindexall

But if you want to reindex only catalog_product_price then you can use below code.

php shell/indexer.php --reindex catalog_product_price
like image 26
Kartik Maniyar Avatar answered Sep 23 '22 08:09

Kartik Maniyar