Skip to content

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

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.

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

No one assigned

    Labels

    Area: FrameworkComponent: InventoryIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions