magento2
magento2 copied to clipboard
Coupon is applied properly on cart but not on checkout
Preconditions and environment
- 2.4.6-p4
- Luma theme
- Default checkout
Steps to reproduce
- Create a cart rule where the user can add two products from different manufactures but is supposed to receive a discount only on one
- The rule uses a COUPON CODE
- Example conditions
- Example actions
- Try to apply the coupon on cart and it works
- Try to go to checkout and apply it
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”.
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:
@magento give me 2.4-develop instance- upcoming 2.4.x release- For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this - To learn more about issue processing workflow, refer to the Code Contributions.
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.
@magento give me 2.4.6-p4 instance
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: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
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:
-
- Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
-
- Verify that issue has a meaningful description and provides enough information to reproduce the issue.
-
- Add
Area: XXXXXlabel to the ticket, indicating the functional areas it may be related to.
- Add
-
- Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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!
- Verify that the issue is reproducible on
- Join Magento Community Engineering Slack and ask your questions in #github channel.
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:
- Create a cart rule where the user can add two products from different manufactures but is supposed to receive a discount only on one
- The rule uses a COUPON CODE
- Add conditions and actions.
- On the UI, add the product with Manufacture with couponcode
- Apply coupon code on cart
- Apply coupon code on checkout
Please refer the screenrecording.
Uploading 38746-1 (1).mov…
@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.
@magento give me 2.4-develop instance
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
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.
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?
@magento give me 2.4.7 instance
Hi @ioweb-gr. Thank you for your request. I'm working on Magento instance for you.
@magento give me 2.4-develop instance
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