Open
Description
Preconditions and environment
- Magento 2.4.x with MSI enabled
- Module: magento/module-inventory-bundle-product
- PHP 7.4 / 8.1 (any)
- Database: MySQL 8.0
Steps to reproduce
-
Setup
- Create a Bundle product with two or more child SKUs that are out of stock in the current MSI stock (so
inventory_stock_<id>.is_salable = 0
). - Ensure that
\Magento\InventorySalesApi\Api\AreProductsSalableInterface::execute()
returnsfalse
for those SKUs.
- Create a Bundle product with two or more child SKUs that are out of stock in the current MSI stock (so
-
Trigger the SQL
- On the storefront (or in a debugger), load the bundle product page so Magento builds the bundle-selection collection.
-
Inspect the generated SQL
- Look for the AdaptAddQuantityFilterPlugin filter clause. You’ll see something like:
… AND e.sku NOT IN('SKU1,SKU2')
- Look for the AdaptAddQuantityFilterPlugin filter clause. You’ll see something like:
-
Observe the bug
- Because the two SKUs are concatenated into one quoted string, neither SKU1 nor SKU2 is actually excluded.
Expected result
The SQL should exclude each SKU individually:
e.sku NOT IN ('SKU1','SKU2')
Actual result
Out-of-stock SKUs are not excluded, because:
// in AdaptAddQuantityFilterPlugin
if ($skusToExclude) {
$subject->getSelect()->where('e.sku NOT IN(?)', implode(',', $skusToExclude));
}
turns ['SKU1','SKU2']
into the single string "SKU1,SKU2"
, resulting in:
e.sku NOT IN ('SKU1,SKU2') -- only one entry, never matches SKU1 or SKU2
Additional information
Proposed fix
IN
vendor/magento/module-inventory-bundle-product/Plugin/Bundle/Model/ResourceModel/Selection/Collection/AdaptAddQuantityFilterPlugin.php
Replace
if ($skusToExclude) {
$subject->getSelect()
->where('e.sku NOT IN(?)', implode(',', $skusToExclude));
}
With
if ($skusToExclude) {
// pass the array directly so Zend_Adapter expands it into individual, quoted literals
$subject->getSelect()
->where('e.sku NOT IN(?)', $skusToExclude);
}
This lets the DB adapter render
e.sku NOT IN ('SKU1','SKU2')
Additional context
This bug causes unsalable children to slip into the “max price” calculation for bundle products and can lead to incorrect price ranges on both product and category pages.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmedA defect with this priority could have functionality issues which are not to expectations.Indicates original Magento version for the Issue report.The issue has been reproduced on latest 2.4-develop branchIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
Type
Projects
Status
Ready for Development