Skip to content

AdaptAddQuantityFilterPlugin: incorrect SKUs exclusion due to imploded string in NOT IN clause #3426

Open
@ChickenBenny

Description

@ChickenBenny

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

  1. 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.
  2. Trigger the SQL

    • On the storefront (or in a debugger), load the bundle product page so Magento builds the bundle-selection collection.
  3. Inspect the generated SQL

    • Look for the AdaptAddQuantityFilterPlugin filter clause. You’ll see something like:
      AND e.sku NOT IN('SKU1,SKU2')
  4. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions