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() returns false for those SKUs.
-
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')
-
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.
Preconditions and environment
Steps to reproduce
Setup
inventory_stock_<id>.is_salable = 0).\Magento\InventorySalesApi\Api\AreProductsSalableInterface::execute()returnsfalsefor those SKUs.Trigger the SQL
Inspect the generated SQL
Observe the bug
Expected result
The SQL should exclude each SKU individually:
Actual result
Out-of-stock SKUs are not excluded, because:
turns
['SKU1','SKU2']into the single string"SKU1,SKU2", resulting in:Additional information
Proposed fix
IN
Replace
With
This lets the DB adapter render
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.