magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Coupon is applied properly on cart but not on checkout

Open ioweb-gr opened this issue 1 year ago • 6 comments

Preconditions and environment

  • 2.4.6-p4
  • Luma theme
  • Default checkout

Steps to reproduce

  1. Create a cart rule where the user can add two products from different manufactures but is supposed to receive a discount only on one
  2. The rule uses a COUPON CODE
  3. Example conditions image
  4. Example actions image
  5. Try to apply the coupon on cart and it works image
  6. Try to go to checkout and apply it image

Expected result

The coupon is properly applied

Actual result

The coupon is not applied

Additional information

No response

Release note

No response

Triage and priority

  • [X] 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”.

ioweb-gr avatar May 23 '24 05:05 ioweb-gr

Hi @ioweb-gr. 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:


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

m2-assistant[bot] avatar May 23 '24 05:05 m2-assistant[bot]

@magento give me 2.4.6-p4 instance

ioweb-gr avatar May 23 '24 05:05 ioweb-gr

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

Hi @ioweb-gr, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar May 23 '24 05:05 m2-assistant[bot]

Hi @engcom-Dash. 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:

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    1. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

m2-assistant[bot] avatar May 24 '24 05:05 m2-assistant[bot]

Hi @ioweb-gr

Thanks for reporting and collaboration.

Verified the issue on magento 2.4 dev instance but the issue is not reproducable.

The coupon is applied succesfully on both cart and checkout.

Steps to reproduce:

  1. Create a cart rule where the user can add two products from different manufactures but is supposed to receive a discount only on one
  2. The rule uses a COUPON CODE
  3. Add conditions and actions.
  4. On the UI, add the product with Manufacture with couponcode
  5. Apply coupon code on cart
  6. Apply coupon code on checkout

Please refer the screenrecording.

Uploading 38746-1 (1).mov…

engcom-Dash avatar May 28 '24 12:05 engcom-Dash

@engcom-Dash I cannot see the video, the attached screen recording is broken. Can you please show me the cart rule settings? From your description of the problem I can see that the rule isn't exactly what I've shown. The product needs to also belong to a specific category. Please confirm that the rules are correct.

I also have a problem deploying an instance for 2.4.6 p4 with magento bot.

ioweb-gr avatar May 28 '24 14:05 ioweb-gr

@magento give me 2.4-develop instance

engcom-Dash avatar May 29 '24 07:05 engcom-Dash

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

Hi @engcom-Dash, here is your Magento Instance: https://c6939cdbaf717e2e390d09bcff2162b3.instances-prod.magento-community.engineering Admin access: https://c6939cdbaf717e2e390d09bcff2162b3.instances-prod.magento-community.engineering/admin_3fae Login: 4986b2ea Password: 1c049f5c53bb

Hi @ioweb-gr

Verified the issue again in magneto 2.4 dev instance. But the issue is not reproducable.

Able to apply the coupon code in both cart and checkout page

The rule has manufacturer and product belonging to a specific category.

Please refer the attached screenshots and recording.

https://github.com/magento/magento2/assets/60198592/dae32933-5328-4d9c-8d08-3f5c81df9b40

engcom-Dash avatar May 29 '24 10:05 engcom-Dash

Hi @engcom-Dash ,

you've added two products but they are the same product and the rule is applicable to both of them. You need to add one product where the rule is applicable and another where the rule isn't. So the first product should be with manufacturer M1 and the rule is applied, and the second with manufacturer M2 and the rule isn't valid for this product.

ioweb-gr avatar Jun 01 '24 13:06 ioweb-gr

While trying to debug this I notice it fails here


    /**
     * Validate coupon code.
     *
     * @param \Magento\Quote\Model\Quote $quote
     * @return $this
     */
    protected function _validateCouponCode(\Magento\Quote\Model\Quote $quote)
    {
        $code = $quote->getData('coupon_code');
        if ($code !== null && strlen($code)) {
            $addressHasCoupon = false;
            $addresses = $quote->getAllAddresses();
            if (count($addresses) > 0) {
                foreach ($addresses as $address) {
                    if ($address->hasCouponCode()) {
                        $addressHasCoupon = true;
                    }
                }
                if (!$addressHasCoupon) {
                    $quote->setCouponCode('');
                }
            }
        }
        return $this;
    }

While validating the code it's trying to check both shipping / billing address to verify if the coupon code is set. However, the coupon code is only set in the quote earlier

\Magento\Quote\Model\CouponManagement::set

        try {
            $quote->setCouponCode($couponCode);
            $this->quoteRepository->save($quote->collectTotals());
        } catch (LocalizedException $e) {
            throw new CouldNotSaveException(__('The coupon code couldn\'t be applied: ' .$e->getMessage()), $e);
        } catch (\Exception $e) {
            throw new CouldNotSaveException(
                __("The coupon code couldn't be applied. Verify the coupon code and try again."),
                $e
            );
        }

So basically I'm assuming that the $quote->setCouponCode($couponCode); should also trigger setting the coupon code into the address itself. But it doesn't

Could you point me to where the coupon code should be set in the address to see why it's not being set?

ioweb-gr avatar Jun 01 '24 13:06 ioweb-gr

@magento give me 2.4.7 instance

ioweb-gr avatar Jun 01 '24 13:06 ioweb-gr

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

@magento give me 2.4-develop instance

ioweb-gr avatar Jun 01 '24 13:06 ioweb-gr

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

Hi @ioweb-gr, here is your Magento Instance: https://7857dcfddb63bdcae5c6a22ded0862ab.instances-prod.magento-community.engineering Admin access: https://7857dcfddb63bdcae5c6a22ded0862ab.instances-prod.magento-community.engineering/admin_7cb0 Login: c1622ff9 Password: 08cf0d872131

Hi @ioweb-gr, here is your Magento Instance: https://c6939cdbaf717e2e390d09bcff2162b3.instances-prod.magento-community.engineering Admin access: https://c6939cdbaf717e2e390d09bcff2162b3.instances-prod.magento-community.engineering/admin_9849 Login: f37e119c Password: c48e2e68f223

OK we found the culprit. There was a free shipping rule above X amount. When adding the two products, the free shipping rule was activating and preventing subsequent rules processing. Moreover, this was not enforced on cart but only on checkout hence the confusion.

After upgrading to 2.4.7 to test our instance, this difference was eliminated and our coupon was not applying in both cart and checkout which was correct due to the settings on the free shipping rule.

So there is an actual problem in 2.4.6-p4 where this use case causes mismatch but it's solved in 2.4.7.

We can safely close this issue

ioweb-gr avatar Jun 01 '24 14:06 ioweb-gr