magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.58k stars 9.32k forks source link

Issue with multiple percentage discounts #39036

Open serhiikv opened 3 months ago

serhiikv commented 3 months ago

Preconditions and environment

Steps to reproduce

1. Create new cart price rules with the following configuration

Rule 1:

Rule Name: 10% Fix Discount
Coupon: No Coupon
Conditions: Apply for all product
Action: 
    Apply: Percent of product price discount
    Discount Amount: 10

Rule 2:

Rule Name: 3% Fix Discount
Coupon: No Coupon
Conditions: Apply for all product
Action: 
    Apply: Percent of product price discount
    Discount Amount: 3
  1. Order product with price = $12
  2. Query REST endpoint orders/{id} for this order

Expected result

In API response receive discount_percent equals 12.7

Actual result

In API response receive discount_percent equals 13

Additional information

Screenshot 2024-08-12 at 11 14 55

Magento2 REST api for orders has one field for discount_percent. In case when order has multiple discounts they are just added. This results in incorrect calculation.

e.g. order amount 12. discount1 = 10%, discount2 = 3%. How magento2 does calculation:

12 - (12 * 0.1) = 10.8 // calculate 10%
10.8 - (10.8 * 0.03) = 10.476 // next calculate 3%
12 - 10.476 = 1.524 // total discount

But if API response is used to calculate discount - it will result in wrong discount amount:

12 - (12 * 0.13) = 10.44 // calculate 13% provided by API field `discount_percent`
12 - 10.44 = 1.56 // total discount is different

The correct discount_percent in this case would be 12.7:

12 - (12 * 0.127) = 10.476 
12 - 10.476 = 1.524 // correct discount amount

Is it possible to change logic behind discount_percent field in REST API response in case of multiple discounts?

Release note

No response

Triage and priority

m2-assistant[bot] commented 3 months ago

Hi @serhiikv. 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:

m2-assistant[bot] commented 3 months ago

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:

engcom-Bravo commented 3 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 months ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 months ago

Hi @engcom-Bravo, here is your Magento Instance: https://16d879d04480f916c2d2f786540d1680.instances-prod.magento-community.engineering Admin access: https://16d879d04480f916c2d2f786540d1680.instances-prod.magento-community.engineering/admin_38e1 Login: 765294e7 Password: 49ec4bb9a057

engcom-Bravo commented 3 months ago

Hi @serhiikv,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Screenshot 2024-08-14 at 14 46 20

In API response receive discount_percent equals 13

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 3 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12754 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.