Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Rounding / order of operation when calculating current_total_discounts and total_discounts

Rounding / order of operation when calculating current_total_discounts and total_discounts

sashakaveri
Visitor
2 0 0

Hi, I am trying to calculate the discount amount on an order, and wondering why the number in my data warehouse diverges from that in the Shopify platform by a couple of pennies here and there.

 

It appears that the calculation of current_total_discounts from the Shopify API could have a slightly different order of operations vs. the calculation in Shopify platform. For example, I have a value of £17.16 being reported in the Shopify platform but £17.18 from the API (after VAT removal). 

 

I think this is down to rounding -- in Shopify UI I think the rounding is applied at the unit level perhaps, and then we sum to get total discounts. From the API, I can only see discount aggregated to the line 'type' level, i.e if someone purchased 4 of the same item, that would be aggregated to one line in the order_line_item table with a quantity field of 4.  I found this answer which explains the rounding happening in the Shopify platform, but it doesn't seem to carry through to the API. 

 

If anyone knows how to re-calculate the current_total_discounts so that it matches the number in the Shopify platform, I'd appreciate any guidance / tips!  Thanks!

 

Reply 1 (1)

sashakaveri
Visitor
2 0 0

I found this article too which explains the problem again, but it doesn't tell me how I can replicate the number I see in the Shopify platform / exports by using the data from the API