24

What is the proper way to reindex a single item after modifications have been made to it.

Example context:

Our company relies on a third party inventory management platform called Stone Edge. We also sell items on multiple storefronts those include Magento, Amazon, Ebay and Buy.com

Once every 10 minutes Stone Edge will download all orders from the sites and then send the inventory adjustments back to our Magento store. This is done by sending a simple http request to a php script stored on our webserver with an array of key value pairs for each of the items in inventory that have had an inventory change since the last update.

After the save function is completed on each of these, the item is then re-indexed so as not to reflect a 0 inventory in-between the time of the update and the next sitewide re-index.

I've located on the Magento forums discussion about how to re-index the item:

$item->setForceReindexRequired(true);
Mage::getSingleton('index/indexer')->processEntityAction($item,Mage_CatalogInventory_Model_Stock_Item::ENTITY,Mage_Index_Model_Event::TYPE_SAVE);

Prior to this set of instructions you would see something like

$item = Mage::getModel('cataloginventory/stock_item')->loadByProduct($entityid);
$item->addQty($change);
$item->save();

However, after completing this, a problem became apparent. The items themselves were re-indexed, but if they were a member of a grouped product, then the group product was not updated.

There is an obvious issue that I will need to address. What is the best approach to this problem?

I will post an answer if I happen to come up with one.

Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120
ajameswolf
  • 1,650
  • 4
  • 21
  • 43
  • This would reindex stock quantities only, right? Could similar code be used to update `catalog_product_flat` and `catalogsearch_fulltext` indexes after importing product data? I.e. could it insert new rows and/or modify existing ones? – Buttle Butkus Feb 18 '14 at 06:27
  • I am still looking for an answer to Buttle's question about applying this to other indexes, in particular catalog_product_flat. Anyone? – spadeworkers Oct 20 '14 at 16:44

2 Answers2

1

Kindly note that the production collection related to grouped product will try to join the price index. So you would need to run the price index and then you would see the result. To run only price index you can run, got to magento root folder and then:

php shell/indexer.php --reindex catalog_product_price

Best of luck !

Bijeesh K G
  • 181
  • 2
  • 9
0

First of all, thanks for the per-product reindex code. Was looking for that.

As for updating the parents, I would collect the parent ID's of products in an array when updating the simple products.

$masterIds[] = Mage::getModel('catalog/product_type_configurable') ->getParentIdsByChild( $product->getId() )

And when you're done with the simple products, just go over the masters and set them up to be reindexed as well with ->setForceReindexRequired(true)