Magento – checkQuoteItemQty using wrong qty for configurable product

event-observerinventory

I have a configurable product with associated simple products which I want to keep Inventory of. I set all the inventories to 10.

I've noticed that if I try to add 4 products to my cart, it won't let me. It says The requested quantity for [product] is not available.

I started digging for a solution.
I found that in app/core/Mage/CatalogInventory/Model/Stock/item.php in the function checkQuoteItemQty, I'm getting funny values.

This function gets called from the observer located one folder up, Observer.php.

I started logging the parameters fed to checkQuoteItemQty and have found that it is squaring my requested quantities. If I order 3 products, it checks inventory for 9. When I order 4, it looks for 16 (which is above the limit of 10).

The observer runs for each Item in the quote. The quote has the simple product AND the configurable product in it. And the observer has a line
$rowQty = $quoteItem->getParentItem()->getQty() * $qty; that is multiplying the two, and yielding the incorrect rowQty.

This seems too asinine to be the default behavior. Do I have something configured wrong? Why are the simple AND configurable products in the quote? Or why do they both have an qty value (of 4, in my case)

Best Answer

I modified core to fix this.

I know it's bad practice and maybe there's a downside. But I did this months ago and I don't think we've noticed any other problems...

Near line 478 in the Observer.php file, I commented out the original code and replaced it with my own that does not containt the * $qty. Here it is:

/**
 * This change made by __[myname]______ because the Qty was being squared
 */
 //$rowQty = $quoteItem->getParentItem()->getQty() * $qty;
 $rowQty = $quoteItem->getParentItem()->getQty();

Good luck.