Skip to content

Discard subsequent rules for shipping amount #37985

Open
@aleneapen

Description

@aleneapen

Preconditions and environment

  • Magento version: 2.4.x
  • Anything else that would help a developer reproduce the bug:

Steps to reproduce

  1. Create the first cart price rule:
    Rule Information:
    Active: Yes
    Coupon: Specific Coupon
    Coupon Code: 50OFF
    Priority: 0
    Condition: None
    Actions
    Apply: Percent of product price discount
    Discount Amount: 50%
    Maximum Qty Discount is Applied To: 0
    Discount Qty Step (Buy X): 0
    Apply to Shipping Amount: No
    Discard subsequent rules: Yes

  2. Create the second cart price rule
    Rule Information:
    Active: Yes
    Coupon: No Coupon
    Priority: 1
    Condition:
    If trial SKU is in cart
    Actions
    Apply: Percent of product price discount
    Discount Amount: 100%
    Maximum Qty Discount is Applied To: 1
    Discount Qty Step (Buy X): 0
    Apply to Shipping Amount: Yes
    Discard subsequent rules: Yes

  3. Add to cart 2 products: first product = trial SKU, second product = non-trial SKU.
    The second rule applies
    Trial SKU price: $20
    Non-trial SKU price: $100
    Shipping: $10
    Subtotal: $130
    Discount: -$30.00

  4. Apply Discount Code: 50OFF
    The first rule is applied correctly but the second rule's shipping discount is applied incorrectly
    Trial SKU price: $20
    Non-trial SKU price: $100
    Shipping: $10
    Subtotal: $130
    Discount: -$70

Expected result

Discount in step 4 should be $60

Actual result

Discount in step 4 is incorrect: $70

Additional information

This seems to be a problem in Magento\SalesRule\Model\Validator::processShippingAmount

Changing lines 334

    foreach ($this->getRules($address) as $rule) {
        /* @var Rule $rule */
        if (!$rule->getApplyToShipping() || !$this->validatorUtility->canProcessRule($rule, $address)) {
            continue;
        }

to

    foreach ($this->getRules($address) as $rule) {
        /* @var Rule $rule */
        if (!$rule->getApplyToShipping()) {
            if ($rule->getStopRulesProcessing()) {
                break;
            }
            continue;
        }
        
        if (!$this->validatorUtility->canProcessRule($rule, $address)) {
            continue;
        }

seems to fix the issue.

Release note

Discard subsequent cart price rules for shipping amount discounts

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S1 - Affects 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: Cart & CheckoutComponent: CheckoutIssue: 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.Progress: ready for devReported 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 branch

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions