Skip to content

Commit

Permalink
Limit post-checkout stock re-index to only products that manage stock… (
Browse files Browse the repository at this point in the history
#562)

* Limit post-checkout stock re-index to only products that manage stock. ref #152

* Restrict collection to just one column in result. Cast id values to int prior to usage in SQL IN statement
  • Loading branch information
ProxiBlue authored and colinmollenhour committed Nov 21, 2018
1 parent 1a4a7d4 commit b3cabc2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/code/core/Mage/CatalogInventory/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,21 @@ public function reindexQuoteInventory($observer)
}
}

/**
* ref: https://github.com/OpenMage/magento-lts/issues/152
*
* get product stock setup.
* We only want to re-index products that actually have stock management setup.
* This limits the number of stock re-indexing that takes place,
* especially in stores where stock is not managed
**/
$productIds = array_map('intval', $productIds);
$stockCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
->addFieldToFilter('product_id', array('in' => $productIds))
->addFieldToFilter('manage_stock', array('eq' => 1));
$stockCollection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns(['product_id']);
$productIds = $stockCollection->getColumnValues('product_id');

if (count($productIds)) {
Mage::getResourceSingleton('cataloginventory/indexer_stock')->reindexProducts($productIds);
}
Expand Down

0 comments on commit b3cabc2

Please sign in to comment.