3

I experienced the following behavior in Magento 1.7.0.2:

  1. Edit product
  2. Go to inventory tab
  3. View inventory

In my test inventory on the product was sitting at 9 units.

  1. I place an order for the product on the front-end whilst keeping the product edit page open
  2. After the order is placed, I click Save on the product edit page (while inventory is still at 9)

Now inventory is sitting on 7 (in other words, 2 units deducted) even though only 1 was ordered.

I repeated this by placing the order in a similar fashion in the back-end, and experienced the same behavior.

Is this just me or do your sites behave similarly? If so, how can this be resolved? I haven't found any official bug report.

Edit: If you view the product inventory level in a new tab after having just placed the order, it seems like the stock level is correct. However, once you click Save on your open tab (whilst editing), the inventory is then reduced by 2 units.

Edit 2: I've posted what I think may be the solution to this issue.

  • So am I correct in saying that the answer I posted is a solution?

  • Can anybody think of any problems this change may have?

  • What exactly were the dev team thinking with the setQtyCorrection method?

  • I would expect it the other way around? If you place an order and then save, the stock is back to 9 instead of 8? – Fabian Blechschmidt Dec 9 '14 at 14:52
  • I was also under the same impression. Could you by chance check this on your staging site? – Moose Dec 9 '14 at 14:53
3

So I tracked this down into app/code/core/Mage/CatalogInventory/Model/Observer.php.

The event catalog_product_save_after calls the saveInventoryData method which in turn calls the _prepareItemForSave method.

Around line 225:

$originalQty = $product->getData('stock_data/original_inventory_qty');
if (strlen($originalQty)>0) {
    $item->setQtyCorrection($item->getQty()-$originalQty);
}

If you comment out this line:

$item->setQtyCorrection($item->getQty()-$originalQty);

It seems to correct the problem & stock levels now stay correct when saving a product whilst simultaneously creating / canceling an order on both the front & back-end of the website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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