cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with multiple percentage discounts

Issue with multiple percentage discounts

Screenshot 2024-08-12 at 11.14.55.png

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?

2 REPLIES 2

Re: Issue with multiple percentage discounts

How Magento does calculation actually depends on the rule priority. If you have 2 rules with the same priority level - one with 10% discount, other with 3% discount, Magento will also calculate it as 13% discount. 

 

What you described as Magento's behaviour is only true if the discount1 was of higher priority than discount2.

Founder at https://agency418.com

Re: Issue with multiple percentage discounts

Thanks for reply.

This is what i get in magento2 shop:

magento2_discount_calc.png

First is applied 10%, and then applied 3%.

But in API response i get 

"discount_percent": 13,