Magento 2

Magento 2 Multi-Shipping Bug: Unpacking the Virtual Bundle Double-Count Glitch

Technical diagram of Magento 2 QuantityCollector double-counting virtual bundles
Technical diagram of Magento 2 QuantityCollector double-counting virtual bundles

Unraveling a Hidden Magento 2 Multi-Shipping Flaw: The Virtual Bundle Double-Count

At Shopping Mover, we understand that a seamless checkout experience is the cornerstone of any successful e-commerce business. Magento 2, whether Adobe Commerce or Open Source, provides a robust platform, but even the most sophisticated systems can harbor subtle bugs that disrupt critical functionalities. One such issue, recently highlighted in Magento GitHub issue #41864, reveals a critical flaw in multi-shipping calculations involving virtual bundle products. This isn't just a minor glitch; it's a bug that can directly impact customer experience and sales for stores running Magento 2.4.x.

As experts in Magento migration and development, we're here to break down this complex issue, explain its technical underpinnings, and provide actionable insights for merchants and developers.

The Scenario: When Multi-Shipping Unexpectedly Fails

Imagine a customer on your Magento 2.4.x store. They've added a few items to their cart:

  • A bundle product, configured to "Ship Bundle Items: Separately." Crucially, all the selections within this bundle are virtual products (e.g., digital downloads, services, warranties).
  • At least one simple, physical product.

Since the cart contains a physical item, the customer expects to see the "Check Out with Multiple Addresses" link, a valuable feature for B2B clients or gift-givers. However, after a seemingly innocuous event – like an administrator updating the price of the simple product in the backend, which triggers a quote recalculation (`quote.trigger_recollect = 1`) – the multi-shipping option vanishes, or worse, clicking it redirects the customer back to the cart with an error message: "The current cart does not match multi shipping criteria, please review or contact the store administrator."

This frustrating experience stems from an incorrect calculation of virtual item quantities, making the system believe there are no physical items eligible for multi-address shipping.

Diving Deep: The Technical Root Cause of Double-Counting

The heart of this problem lies within the Magento 2 core, specifically in the Magento\Quote\Model\Quote\QuantityCollector::collectItemsQtys() method. This method is responsible for accurately tallying the quantities of virtual and physical items in the cart, which is crucial for determining multi-shipping eligibility.

Here's the breakdown of the bug:

  1. Virtual Bundle Identification: When a bundle product has all its selections configured as virtual products, Magento's Magento\Bundle\Model\Product\Type::isVirtual() method correctly identifies the bundle itself as virtual.
  2. Ship Separately Logic: For bundles set to "Ship Bundle Items: Separately," the QuantityCollector iterates through the bundle's child items. If a child is virtual, its quantity (child qty x parent qty) is added to virtual_items_qty.
  3. The Double-Count: The bug occurs because, immediately after counting the virtual children, the QuantityCollector then checks if the parent bundle product itself is virtual. Since it is (as all its children are virtual), its quantity is also added to virtual_items_qty. This results in the bundle's quantity being counted twice: once for its virtual children and once for the bundle parent itself.

Consider our example: a bundle with two virtual children, added with a quantity of 2. The expected virtual_items_qty should be 4 (2 children x bundle qty 2). However, due to the double-counting, it becomes 6 (4 from children + 2 from the bundle parent).

This inflated virtual_items_qty then feeds into Magento\Multishipping\Helper\Data::isMultishippingCheckoutAvailable(). This helper checks if getItemsSummaryQty() - getItemVirtualQty() > 0. In our scenario, if getItemsSummaryQty() (total items, including the physical one) is 5 and getItemVirtualQty() is incorrectly reported as 6, the condition becomes 5 - 6 = -1, which is not greater than 0. Thus, multi-shipping is deemed unavailable.

The bug is particularly insidious because virtual_items_qty is not persisted. It only manifests when totals are explicitly recollected, such as when quote.trigger_recollect = 1 is set after an admin action or during specific page loads.

The Elegant Solution: A Simple elseif

The fix, proposed by the community, is surprisingly straightforward: changing an if statement to an elseif within the QuantityCollector. This ensures that if the bundle's virtual children have already been counted because the bundle is set to "Ship Bundle Items: Separately," the parent bundle itself isn't counted again as a separate virtual item.

// Original problematic code snippet (simplified for illustration)
if ($item->getIsVirtual()) {
$virtualItemsQty += $item->getQty();
} else if ($item->getIsBundle() && $item->getShipSeparately()) {
foreach ($item->getChildren() as $child)
if ($child->getIsVirtual()) {
$virtualItemsQty += $child->getQty() * $item->getQty();
}
}

// Proposed fix (conceptual)
if ($item->getIsBundle() && $item->getShipSeparately()) {
foreach ($item->getChildren() as $child)
if ($child->getIsVirtual()) {
$virtualItemsQty += $child->getQty() * $item->getQty();
}
} elseif ($item->getIsVirtual()) { // Changed to elseif
$virtualItemsQty += $item->getQty();
}

This small but critical change aligns the logic with how Quote::getItemsSummaryQty() already handles bundles, preventing the erroneous double-counting.

Why This Matters for Your Magento 2.4.x Store and Migrations

For merchants operating on Magento 2.4.x (including 2.4.7-p10, 2.4.9, and 2.4-develop), this bug can lead to:

  • Lost Sales: Customers unable to use multi-shipping for mixed carts might abandon their purchase.
  • Customer Frustration: A broken checkout flow erodes trust and negatively impacts user experience.
  • Operational Inefficiencies: Support teams may spend valuable time troubleshooting issues that are core platform bugs.
  • Inaccurate Reporting: Incorrect quantity calculations can skew inventory and sales data.

If you're planning a Magento migration, especially to a 2.4.x version, understanding and addressing such core bugs is paramount. A successful migration isn't just about moving data; it's about ensuring your new platform is stable, performant, and free from known issues. Thorough testing of all checkout paths, particularly those involving complex product types like bundles and multi-shipping, is non-negotiable.

Actionable Advice from Shopping Mover

As your trusted e-commerce migration experts, Shopping Mover recommends the following:

  • Stay Updated: Always aim to apply the latest Magento patches and updates. Adobe Commerce and Open Source releases frequently include bug fixes.
  • Thorough Testing: Implement comprehensive testing protocols for your checkout process, covering all product types (simple, configurable, bundle, virtual, downloadable) and shipping scenarios (single address, multi-address).
  • Review Customizations: If you have custom modules or integrations that interact with quote or checkout processes, ensure they are compatible with core Magento logic and don't inadvertently trigger or exacerbate such bugs.
  • Professional Audit: Consider a professional Magento audit from experts like Shopping Mover. We can identify potential vulnerabilities and performance bottlenecks, ensuring your platform is robust.

This virtual bundle multi-shipping bug is a prime example of how seemingly minor code discrepancies can have significant business impacts. Proactive identification and resolution are key to maintaining a healthy and high-performing Magento store.

Don't let hidden bugs derail your e-commerce success. Contact Shopping Mover today for expert Magento development, migration, and optimization services, ensuring your checkout experience is always flawless.

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools