magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Discard subsequent rules for shipping amount #37985

Open aleneapen opened 1 year ago

aleneapen commented 1 year ago

Preconditions and environment

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

m2-assistant[bot] commented 1 year ago

Hi @aleneapen. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

aleneapen commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @aleneapen. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @aleneapen, here is your Magento Instance: https://f8fd22f80ea4faaa323e4d586df0fa8c.instances-prod.magento-community.engineering Admin access: https://f8fd22f80ea4faaa323e4d586df0fa8c.instances-prod.magento-community.engineering/admin_fdb3 Login: 8e65dffe Password: 68751eaaf747

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://f8fd22f80ea4faaa323e4d586df0fa8c.instances-prod.magento-community.engineering Admin access: https://f8fd22f80ea4faaa323e4d586df0fa8c.instances-prod.magento-community.engineering/admin_53ef Login: 301ba636 Password: 20786fa664a5

engcom-Bravo commented 1 year ago

Hi @aleneapen,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

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

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

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

It is working fine here.

Screenshot 2023-09-13 at 3 23 46 PM

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

Screenshot 2023-09-13 at 3 24 20 PM

Here discount $70 is getting applied Could you please elaborate how discount should be $60.

Thanks.

aleneapen commented 1 year ago

Hi @engcom-Bravo, here is my thinking: the discount should be $60 because the second rule shipping discount shouldn't apply.

Since the first rule had priority = 0 and Discard subsequent rules: Yes, and Apply to shipping Amount = No so the second rule shouldn't apply.

Is that the intended behaviour?

engcom-Bravo commented 1 year ago

Hi @aleneapen,

Thanks for your update.

Here i have deactivated the second price rule it is working fine here.Discount is $60

Screenshot 2023-09-14 at 3 54 02 PM

As per the document https://experienceleague.adobe.com/docs/commerce-admin/marketing/promotions/cart-rules/price-rules-cart-create.html?lang=en#step-1%3A-add-a-rule

The Priority setting is important when two cart rules/coupon codes are valid for the same product at the same time. The rule with the highest Priority setting (1 being the highest) controls the cart action

When we are applying both cart price rules

Screenshot 2023-09-14 at 6 33 54 PM

As per devdocs second cart price rule should apply to product with 20$ with having priority 1 in that case total discount will be above $70 because it will give 100% discount.could you please check document and please let us know if we are missing anything and elaboarte the steps.

Thanks.

aleneapen commented 1 year ago

Hi @engcom-Bravo, The documentation is unclear. 0 is higher priority than 1.

lower number in priority field = higher priority. 0 is the highest priority image

Also see this comment on a similar issue: https://github.com/magento/magento2/issues/27202#issuecomment-627331528

So technically, the second rule (with priority = 1) shouldn't apply at all in our test case.

engcom-Bravo commented 11 months ago

Hi @aleneapen,

Thanks for your update.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.kindly refer the screenshots.

Screenshot 2023-09-27 at 2 42 14 PM

Discount is applied as $70.As per the documentation https://experienceleague.adobe.com/docs/commerce-admin/marketing/promotions/cart-rules/price-rules-cart-create.html?lang=en#step-1%3A-add-a-rule cart price rule having high priority is should control action.Here second rule should not apply.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 11 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-9612 is successfully created for this GitHub issue.

m2-assistant[bot] commented 11 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.