Magento 2.4.7-p10: Unpacking the Silent Quantity Doubling Bug for Bundle Products
Magento 2.4.7-p10: A Critical Cart Glitch Silently Doubles Bundle Product Quantities
E-commerce platforms thrive on seamless user experiences, especially during checkout. However, a recently reported GitHub issue (Issue #41039) highlights a critical regression in Magento Open Source and Adobe Commerce 2.4.7-p10 that can silently double the quantity of bundle, configurable, and grouped products in the cart, leading to frustrating checkout failures and abandoned carts. This bug, rated S1 for severity, demands immediate attention from merchants and developers.
The Problem: Unseen Quantity Duplication
Imagine a customer adds a bundle product with a quantity of '1' to their cart. Later, during an seemingly unrelated action—such as saving a shipping address or re-saving the quote after total collection—the bundle product's quantity in the cart mysteriously doubles to '2'. This isn't just a visual glitch; the system recalculates all bundle selection requirements based on the doubled parent quantity. If this new quantity exceeds available stock, the item fails validation with "The requested qty is not available," abruptly aborting the entire checkout process.
Unveiling the Root Cause: A Regression from ACSD-46869
The detailed bug report by CreamDevelopment meticulously traces the issue back to a specific change introduced by Adobe's quality patch ACSD-46869. This patch, originally intended to fix a separate bug where bundle option changes weren't persisted without a quantity change, inadvertently removed a crucial guard in Magento\Quote\Model\Quote\Item\CartItemPersister::save().
Previously, the system would only call Quote::updateItem() if the item's quantity had actually changed (if ($currentItem->getQty() !== $buyRequestData->getQty())). With this guard removed, updateItem() is now unconditionally called for any existing item whenever the quote is saved, even if no changes were intended.
The core of the problem lies within how bundle products are handled during this update. Quote::updateItem() attempts to prevent double-counting by calling $buyRequest->setResetCount(true). This mechanism relies on a condition where $item->getId() == $request->getId() to reset the item's quantity before adding the new quantity. However, for bundle products, the DataObject returned by Quote\Item\CartItemOptionsProcessor::getBuyRequest() (via Bundle\Model\CartItemProcessor::convertToBuyRequest()) never sets an ID. Consequently, the resetCount guard is bypassed, and the original quantity is added on top of the item's current quantity, resulting in the silent doubling.
Impact on Merchants and Developers
For merchants, this bug translates directly into lost sales and a degraded customer experience. Customers encountering "out of stock" errors during checkout for items they know are available will likely abandon their carts. For developers, debugging such a silent, intermittent issue can be a nightmare, especially when the trigger is an "unrelated" quote save operation.
Proposed Solutions and an Immediate Workaround
The issue author provided two potential long-term fixes:
- Modify
Quote\Item\CartItemOptionsProcessor::getBuyRequest()(and product-type-specific implementations) to set an ID matching the quote item ID on the returnedDataObject. - Restore a narrower condition in
CartItemPersister::save()to only invokeupdateItem()when actual changes (quantity or options) have occurred.
Crucially, a practical workaround is also available for immediate implementation:
// Example: A before plugin on Quote::updateItem()
// Assuming you have a plugin setup for Magento\Quote\Model\Quote
// In your plugin's beforeUpdateItem method:
public function beforeUpdateItem(
\Magento\Quote\Model\Quote $subject,
$itemId,
\Magento\Framework\DataObject $buyRequest
) {
if (!$buyRequest->getId()) {
$buyRequest->setId($itemId);
}
return [$itemId, $buyRequest];
}
This plugin ensures that the $buyRequest object always has an ID, allowing Magento's existing resetCount guard to function as intended and prevent the quantity from doubling.
Community Response and Next Steps
While the Magento engineering team (engcom-Bravo) reported an inability to reproduce the issue on the "Latest 2.4-develop instance," this does not necessarily mean the bug is absent from 2.4.7-p10. It could imply that a fix has been merged into the development branch for a future release, or that the reproduction steps require a very specific environment. Until an official patch is released for 2.4.7-p10, implementing the provided workaround is highly recommended for any store using bundle, configurable, or grouped products on the affected version.
Staying vigilant with bug reports and community insights like these is vital for maintaining a robust and reliable Magento store. Shopping Mover emphasizes the importance of understanding such core system behaviors, especially when considering upgrades or migrations, to ensure your e-commerce platform performs flawlessly.