-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Wrong discount calculation when using multiple fixed discount cart rules #32964
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
Comments
Hi @tiagosampaio. 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. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
Hi @engcom-Oscar. Thank you for working on this issue.
|
Hi @tiagosampaio ! Thank you for your report. |
1 - Create two products with the price of $19 each (SKUs: test-product-one, test-product-two). The first rule is applied only to the product Configuration: {
"salesrule": [
{
"rule_id" : 5,
"name" : "Test Product Two Discount",
"description" : "",
"from_date" : "2021-05-07",
"to_date" : null,
"uses_per_customer" : 0,
"is_active" : 1,
"conditions_serialized" : "{\"type\":\"Magento\\\\SalesRule\\\\Model\\\\Rule\\\\Condition\\\\Combine\",\"attribute\":null,\"operator\":null,\"value\":true,\"is_value_processed\":null,\"aggregator\":\"all\"}",
"actions_serialized" : "{\"type\":\"Magento\\\\SalesRule\\\\Model\\\\Rule\\\\Condition\\\\Product\\\\Combine\",\"attribute\":null,\"operator\":null,\"value\":\"1\",\"is_value_processed\":null,\"aggregator\":\"all\",\"conditions\":[{\"type\":\"Magento\\\\SalesRule\\\\Model\\\\Rule\\\\Condition\\\\Product\",\"attribute\":\"sku\",\"operator\":\"==\",\"value\":\"test-product-two\",\"is_value_processed\":false,\"attribute_scope\":\"\"}]}",
"stop_rules_processing" : 0,
"is_advanced" : 1,
"product_ids" : null,
"sort_order" : 0,
"simple_action" : "by_fixed",
"discount_amount" : 18.0000,
"discount_qty" : null,
"discount_step" : 0,
"apply_to_shipping" : 0,
"times_used" : 0,
"is_rss" : 1,
"coupon_type" : 1,
"use_auto_generation" : 0,
"uses_per_coupon" : 0,
"simple_free_shipping" : 0,
"row_id" : 5,
"created_in" : 1,
"updated_in" : 2147483647
}
]}
The second one applies a fixed discount of $10 to the whole cart. {
"salesrule": [
{
"rule_id" : 6,
"name" : "Ten Dollars to Whole Cart",
"description" : "",
"from_date" : "2021-05-07",
"to_date" : null,
"uses_per_customer" : 0,
"is_active" : 1,
"conditions_serialized" : "{\"type\":\"Magento\\\\SalesRule\\\\Model\\\\Rule\\\\Condition\\\\Combine\",\"attribute\":null,\"operator\":null,\"value\":true,\"is_value_processed\":null,\"aggregator\":\"all\"}",
"actions_serialized" : "{\"type\":\"Magento\\\\SalesRule\\\\Model\\\\Rule\\\\Condition\\\\Product\\\\Combine\",\"attribute\":null,\"operator\":null,\"value\":\"1\",\"is_value_processed\":null,\"aggregator\":\"all\"}",
"stop_rules_processing" : 0,
"is_advanced" : 1,
"product_ids" : null,
"sort_order" : 0,
"simple_action" : "cart_fixed",
"discount_amount" : 10.0000,
"discount_qty" : null,
"discount_step" : 0,
"apply_to_shipping" : 0,
"times_used" : 0,
"is_rss" : 1,
"coupon_type" : 2,
"use_auto_generation" : 0,
"uses_per_coupon" : 0,
"simple_free_shipping" : 0,
"row_id" : 6,
"created_in" : 1,
"updated_in" : 2147483647
}
]} 3 - With all set then go to the storefront and add 5 - Apply the coupon code to the cart The version I used for this testing is Magento Commerce 2.4.2-p1 |
@engcom-Oscar any update on this? |
@tiagosampaio Thank you for your reply, with more detailed steps I was able to reproduce this issue and confirmed it. |
The issue is caused by calculation in \Magento\SalesRule\Helper\CartFixedDiscount::getDiscountAmount, there the whole cart price discount is divided between all cart items. So, for the first cart item, total price is 19 - (10 / 2) = $14, and for the second one 19 - (10 / 2) - 18 = -4, that becames $0. Finally, the cart total is 14 + 0 = $14. |
After investigating this issue, we found out that problem caused by wrong sequence of applying cart price rules. Preconditions (*)
Steps to reproduce (*)
Actual result (*)Primarily discount calculating by second rule ($10 for whole cart by coupon) and it using formula sum of discount divided on qty of order items: $10 / 2 = $5 on each product. This make price of both product $19 - $5 = $14, and subtotal of the cart = $28. After this first cart rule applying (minus $18 for one of the product), but because our product price only $14, so discount is only $14, and product's price became 0. Therefore only $24 discount is applied, and the cart total is shown as $14.00. Expected result (*)Primarily discount calculating should be by first cart rule (minus $18 for one of the product), to make product price $19 - $18 = $1, cart total = $20. Then second rule should be applying correctly ($10 for whole cart by coupon), to make cart total $10.00. Total discount amount should be $28.00 |
@magento I am working on this |
@magento give me 2.4-develop instance |
Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you. |
Hi @engcom-Bravo, here is your Magento Instance: https://c0a44b9caa363e941ccaf50aad1a6c7d.instances-prod.magento-community.engineering |
@magento give me 2.4-develop instance |
Hi @engcom-Delta. Thank you for your request. I'm working on Magento instance for you. |
Hi @engcom-Delta, here is your Magento Instance: https://c0a44b9caa363e941ccaf50aad1a6c7d.instances-prod.magento-community.engineering |
Hi @tiagosampaio , Thank you for reporting and collaboration. Steps to reproduce -
|
@engcom-Delta, this still happens in version I have the following cart rules created: Fixed $10.00 to the whole cartFixed $18.00 to a particular categoryWhen I go to the cart page and add the products to my cart I have the following result: The total discount applied to my cart should be The Thanks. |
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
The text was updated successfully, but these errors were encountered: