-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cart price rules - Incorrect discount amount when using fixed discount amount for whole cart #37496
Comments
Hi @vandersonramoslybe. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hi, I've recently experience this problem after upgrading to 2.4.5. It only happens when I try and apply a Fixed amount discount coupon to a quote with a configurable product in it. Considering it's exactly half, my first thought was that the discount is somehow applying to both the Parent and Child product, however, as only 1 of those is taken into account when calculating row totals, it only takes into account half the discount. More evidence for that is from a self developed module that applies loyalty points to products. Only since 2.4.5 has it started applying double the amount to configurable products, as if there were two products in 1 row. Maybe that will help, but I'll be keeping an eye on this issue as well! |
I tested on Magento 2.3.7 as well, same behavior. This is the class used when we have a cart rule as a Whole cart: https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/SalesRule/Model/Rule/Action/Discount/CartFixed.php The value on line 82 $baseRuleTotals = $ruleTotals['base_items_price'] ?? 0.0; contains the price for 2 items instead of only one as expected. For some reason, the method isChildrenCalculated from https://github.com/magento/magento2/blob/2.4.5-p2/app/code/Magento/SalesRule/Model/Validator.php is interfering with the calculation |
@magento give me 2.4-develop instance |
Hi @chernenm. Thank you for your request. I'm working on Magento instance for you. |
Hi @chernenm, here is your Magento Instance: https://301ee372ee8c8fa8afd70181c0924925.instances-prod.magento-community.engineering |
Hi @engcom-Dash. Thank you for working on this issue.
|
I had a nosey through Validator.php. I'm not sure what constitutes a child item as 'calculated' and considering how often that method is referenced I was hesitant to change anything. However, I added an extra line to the if statement on line 464 of the Validator class (function initTotals()) and it seems to have fixed the issue for me, calculating the fixed amount discount correctly when I go to checkout.
I figured, as the statement seems to be including Simple products that are also children, they should be omitted from the calculation. I'll await any further info, currently this is staying safely away from production |
I had proposed a simple fix through Validator.php. I am also interrupting this above if statement but I'm excluding a check
The updated code is below
I have seen that parent and child were getting calculated and amount was getting double the accurate price and then the ratio calculated 0.5 causing discount to get half. I'm not very 100 percent sure this will be optimal solution but I have tested all the scenarios with loggedin and non logged in customers and every possible test case. Everything works fine. |
Hi @engcom-Hotel. Thank you for working on this issue.
|
Hello @vandersonramoslybe, Thanks for the report and collaboration! We have tried to reproduce the issue with the mentioned steps in the main description. We have used the 2.4-develop branch in order to reproduce the issue. But for us, the discount amount is showing $500. Please have a look to the below screenshot for reference: Please review the steps and let us know if we need to do any additional steps in order to reproduce the issue. Thanks |
Do you have a plugin as explained in the description? Step 3 3 - Create a plugin afterGetPrice for the class Magento\Quote\Model\Quote\Item. method getPrice() |
Yes @vandersonramoslybe, Let me attach the same here for reference: Please let me know if we missed anything. Thanks |
Thanks, I installed your plugin. I am running a vanilla Magento 2.4.6. The issue is reproducible with Configurable products. |
Hello @vandersonramoslybe, Thanks for the response! Now we are able to reproduce the issue. Please refer to the below screenshot for reference: Hence confirming the issue. Thanks |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-8853 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue. |
@magento I'm working on this |
Preconditions and environment
Steps to reproduce
Create a Cart price rule:
1 - Marketing -> Promotions -> Cart Price Rules
Conditions:
2 - Actions:
It is important to be: Fixed amount discount for whole cart
3 - Create a plugin afterGetPrice for the class Magento\Quote\Model\Quote\Item. method getPrice()
EXAMPLE:
`<?php
declare(strict_types=1);
namespace Vendor\Module\Plugin;
use Magento\Quote\Model\Quote\Item as QuoteItem;
class GetPriceFromQuoteItemPlugin
{
}`
Choose a configurable product, and add it to the cart. The price will be changed to the new one, after that, apply the coupon code:
Check the discount value.
Expected result
It should be 500.00, not 250.00
Actual result
It is 250.00
Additional information
No response
Release note
No response
Triage and priority
The text was updated successfully, but these errors were encountered: