-
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
Fixed cart discount calculated incorrectly when product first added to cart. #26622
Comments
Thanks for opening this issue! |
Hi @aligent-lturner. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. @aligent-lturner do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?
|
…Id, as the latter is only set in beforeSave function.
@magento give me 2.4-develop instance |
Hi @aligent-lturner. Thank you for your request. I'm working on Magento 2.4-develop instance for you |
Hi @aligent-lturner, here is your Magento instance. |
Luma does not display discounts in minicart, and I do not have access to the underlying database to confirm the issue in the provided vanilla instance. |
Actually - I was able to use the database backup functionality to confirm the issue in vanilla instance: From quote table, after adding 2 $10 items:
Note the values $19.33 (i.e. a discount of $0.67 has been applied, rather than $1) And from the quote_item table:
Here, we can see discounts for the 2 items of $0.33 and $0.34 instead of $0.50 for each. |
Hi @shikhamis11. Thank you for working on this issue.
|
✅ Confirmed by @aligent-lturner |
…, and make function private
Hi @aligent-lturner. Thank you for your report.
The fix will be available with the upcoming 2.4.0 release. |
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
Notes
The issue is also present any time a new simple product is added to the cart. For example, if a different configurable option was chosen, the discount would be calculated as $0.67 (then $0.75 for another). The reason for this behaviour is due to the following:
When a configurable is added to the cart, two items actually get added as Quote items - the configurable, and the simple item representing the selected options.
As part of the rule calculation, it skips child (simple) items by checking the result of
getParentItemId()
:magento2/app/code/Magento/SalesRule/Model/Validator.php
Lines 385 to 388 in e6e6725
However, for a newly added item,
parentItemId
is not set yet, as this is only set in thebeforeSave
function of the quote item:magento2/app/code/Magento/Quote/Model/Quote/Item/AbstractItem.php
Lines 178 to 185 in e6e6725
Instead, the
Validator
class should be checking the result ofgetParentItem
The text was updated successfully, but these errors were encountered: