-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#39036: Issue with multiple percentage discounts #39683
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
base: 2.4-develop
Are you sure you want to change the base?
Conversation
- fixed incorrect discount percent calculation
- change copyright
Hi @quterorta. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
@magento run all tests |
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @quterorta,
Thanks for the contribution!
The changes seems good to me, but I guess we need to adjust the unit test according to this change. And also please fix the failed static tests.
Thanks
@quterorta I am taking care of the test case fixes. Thank You! |
@magento run all tests |
@magento run Unit Tests, Static Tests |
@magento run all tests |
Hi @quterorta, Thanks for the collaboration & contribution! ✔️ QA PassedPreconditions:
Steps to reproduce
Before: ✖️ ![]() After: ✔️ ![]() Builds are failed. Hence, moving this PR to Extended Testing. Thanks. |
@magento run all tests |
@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE |
Two of the Functional EE Test failures are inconsistent and seems to be flaky. They neither part of PR nor failing because of the PR changes. The consistent failure is a known issue. Functional Tests EE: Build 1: Allure Report - EE Build 2: Allure Report - EE Known Issue: StorefrontAssertAsLowAsLabelTest: ACQE-7645 Hence Moving this PR in Merge In Progress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the issue lies in how the discount amount is calculated, not the percentage itself.
Let me give an example.
Suppose we have a product priced at $100 and two price rules:
- 10% discount
- 5% discount
In the Cart Price Rule settings, the Percent of product price discount option is selected.
This setting implies that the discount should be calculated based on the original product price.
So I would expect the final discount to be:
(10% of $100) + (5% of $100) = $10 + $5 = $15
However, the current implementation calculates it like this:
- 10% of $100 = $10
- 5% of ($100 - $10) = 5% of $90 = $4.5
There is no mention in the documentation that the discount is calculated from the cart item total rather than the original product price,
or that on each iteration of applying a Cart Price Rule, the cart item row total
(i.e., product price minus all previously applied rule discounts) is used instead.
cc @sidolov @engcom-Hotel what do you think? |
Hello @Den4ik, You are right, the current discount calculation is working as below:
Please refer to the below screenshot from this page, which says the same thing on discount calculation: |
Hi @engcom-Hotel |
Moving this pull request (PR) to |
Hello @Den4ik, As per our discussion on Slack, your concern is regarding the calculation of two cart price rules, 10% and 5%, applied as
It should calculate as below:
Please confirm, if I understood correct. Thanks |
You understood correctly. I see 2 possible solutions:
|
Hello @Den4ik, We are currently discussing this with the internal team and will update you accordingly. Thanks |
Description (*)
The issue was related to the discount percent calculation in the foreach iteration.
So, when we have multiple rules in the foreach function we apply these rules one-by-one, so discounts we apply one-by-one too, and just summing them is wrong, so I used the next formula for the discount percentage calculation: (X+Y) - ((X*Y) / 100).
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
{base_price} * ((100-{discount_percent})/100)
Questions or comments
Contribution checklist (*)