-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
creditmemo bundle inventory calculation error #275
creditmemo bundle inventory calculation error #275
Conversation
…3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not test but looks good to me.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
Hi guys After applying the patch that products are not re-stocked correctly.
|
@rafaelpatro It's been some time since I last looked at this code (or most any Magento code, as I'm no longer as involved in the dev side of things). Anyway, in the meantime, we've had to expand on this patch due to some other modules we've added related to inventory management. I didn't write this, but the code below is currently running and works as expected for Bundles and Configurable items. Please take a look, and if you confirm it fixes the issues, please feel free to submit it as a new patch as I won't have time to do so.
|
Hi @JonLaliberte But I can't reproduce your issue as you described. public function refundOrderInventory($observer)
{
/* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
$creditmemo = $observer->getEvent()->getCreditmemo();
$items = array();
foreach ($creditmemo->getAllItems() as $item) {
/* @var $item Mage_Sales_Model_Order_Creditmemo_Item */
$return = false;
if ($item->hasBackToStock()) {
if ($item->getBackToStock() && $item->getQty()) {
$return = true;
}
} elseif (Mage::helper('cataloginventory')->isAutoReturnEnabled()) {
$return = true;
}
if ($return) {
$parentOrderId = $item->getOrderItem()->getParentItemId();
/* @var $parentItem Mage_Sales_Model_Order_Creditmemo_Item */
$parentItem = $parentOrderId ? $creditmemo->getItemByOrderId($parentOrderId) : false;
$qty = $parentItem ? ($parentItem->getQty() * $item->getQty()) : $item->getQty();
if (isset($items[$item->getProductId()])) {
$items[$item->getProductId()]['qty'] += $qty;
} else {
$items[$item->getProductId()] = array(
'qty' => $qty,
'item' => null,
);
}
}
}
Mage::getSingleton('cataloginventory/stock')->revertProductsSale($items);
} |
@rafaelpatro Correct, the bundles must contain multiple items for the issue to be noticed. Give this a try and see if you can reproduce the original issue? |
But this is the point. My test is Ok. Check stock qty: 10 So Core code works as expected. I'm not facing issues refunding bundle products. |
@rafaelpatro I don't have a stock install set up to test with myself. I'm not sure if this could be affecting things, but here is how the items in our bundles are set up: (These are "drop-down" type inputs, on the front-end we hide from the customer that it's a bundle.) |
Hmmm my bundle product is configured by dynamic price. |
…ventory_Model_Observer This bug was present begining in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues. Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products. For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.
@JonLaliberte @rafaelpatro I made some tests too and I can confirm that I cannot reproduce the original issue Jon was having with the code from Vanilla Magento. I suggest we rollback that change as it's definitely causing issues. |
+1 for rollback |
As I see there is a request for rollback of this PR. Any other opinions? |
This bug was present beginning in 1.7.0.2 and is still present in 1.9.3.3. This patch has been running in production for about 4 years without any issues.
Code was mis-calcuating the qty of simple items to put back in stock for bundle (and configurable) products.
For example if you had a Bundle X that contained 10 Widgets and the customer ordered 10 of the Bundle X (thus they ordered 100 Widgets), the code previously would multiply twice when issuing a credit memo: When calling $item->getQty() on the Widget product Magento would return 100, since that's how many exist in the order. It would then multiply that by the number of Bundle X in the order (10), and would return 1000 items to the inventory for the Widget, instead of just 100.