Magento 2 Cart Price Rule Bug: Exclude SKU Condition Fails Subtotal Calculation
Unpacking a Critical Magento 2 Cart Price Rule Flaw: When "Exclude SKU" Doesn't Quite Exclude
As e-commerce migration specialists at Shopping Mover, we constantly monitor the pulse of the Magento ecosystem, identifying critical issues that can impact merchants and developers alike. A recently confirmed bug (Issue #40503) on the Magento 2 GitHub repository highlights a significant flaw in how Cart Price Rules handle 'exclude SKU' conditions, specifically affecting subtotal calculations. This issue, reproducible in Magento versions 2.4.7 and 2.4.8, poses a real risk to promotional strategies and revenue accuracy.
The Core Problem: Miscalculated Subtotals in Conditional Logic
The essence of the bug lies in a logical inconsistency within Magento's Cart Price Rule engine. When a rule is configured to apply a discount based on a subtotal threshold, and also includes a condition to 'exclude' specific SKUs from eligibility, the system fails to correctly calculate the subtotal for the conditions evaluation. While the discount action correctly excludes the specified SKU, the initial check for whether the rule should even trigger incorrectly includes the price of the excluded item in the overall cart subtotal.
Consider the reported scenario:
- Rule Setup: A Cart Price Rule is created with two key elements:
- Conditions: "Subtotal greater than or equal to 31" AND "If an item is FOUND in the cart with ALL of the following conditions: SKU is not 24-MB03".
- Actions: "SKU is not 24-MB03" (meaning the discount applies only to items other than 24-MB03).
- Reproduction Steps:
- Add product 24-MB03 (Price: 38.00) to the cart. (Expected: No discount, as this SKU is excluded).
- Add another product 24-MB01 (Price: 30.00) to the cart.
Expected vs. Actual Outcome: A Discrepancy with Real-World Impact
The expected behavior in this scenario is clear: the discount should not be applied. The subtotal of eligible items (i.e., excluding SKU 24-MB03) is 30.00, which falls below the minimum threshold of 31 set in the rule's conditions. Therefore, the rule should not trigger.
However, the actual result reveals a critical flaw. The discount is applied after adding product 24-MB01. This occurs because the rule's condition evaluation appears to be based on the total cart subtotal (38.00 + 30.00 = 68.00), which incorrectly includes the price of the excluded SKU 24-MB03. Only after the order is placed does the system correctly apply the discount solely to SKU 24-MB01, highlighting that the issue is in the condition evaluation, not the discount application itself.
This bug can lead to:
- Unintended Discounts: Merchants might inadvertently offer discounts on orders that don't truly qualify, impacting profit margins.
- Inconsistent Customer Experience: Customers might see a discount applied in the cart, only for it to be adjusted or removed later if other rules or manual checks intervene, leading to frustration.
- Complex Workarounds: Developers might need to implement custom modules or more convoluted rule configurations to bypass this core logic flaw, adding complexity and maintenance overhead.
Community Response and Next Steps
As of the time of this insight, the GitHub issue is marked as "Confirmed" and "Reproduced on 2.4.x," indicating that the Magento core team has acknowledged the validity of the bug. However, no official solution or workaround has been provided within the issue comments (as there are no comments available in the provided source). This means merchants and developers currently running affected Magento 2.4.x versions need to be acutely aware of this limitation when designing their promotional strategies.
For businesses undergoing a migration to Magento 2, or those already operating on it, this bug underscores the importance of rigorous User Acceptance Testing (UAT) for all promotional rules. Relying solely on out-of-the-box functionality for complex pricing logic without thorough verification can lead to costly errors. We recommend testing all Cart Price Rules that combine subtotal conditions with SKU exclusions to ensure they behave as expected.
Shopping Mover will continue to monitor this issue for updates and potential fixes. In the interim, careful rule configuration and custom development might be necessary to ensure promotional accuracy.