Discount Applications exposes line level discounts on the Order API

Shopify Partner
660 0 104

Hi again,

We came across something quite confusing.

It's really not clear how the discount applications relate to the lineitem.total_discount and order.total_discounts properties.

When testing discounts, we see that when using the online store, POS or draft orders, the discount allocation is allocated to line items but lineitem.total_discount always remains 0.

However, we came across an order generated by an app, where the discount amount was in both the discount allocation as well as the lineitem.total_discount. This cause our report to double count to the discount.

Is there a difference between those two scenarios? Is lineitem.total_discount deprecated?

If so, are orders that were placed before the discounts allocations release being changed to change to add the discount allocations property to them?

0 Likes
Shopify Staff
Shopify Staff
16 0 0

Hi Clement!

order.total_discount will always contain the sum of all discounts so it is safe to use it.

line_item.total_discount will indeed be eventually deprecated as it represents discounts "showing on the line item". In other words, it's a presentation concern baked in the API as all discounts are actually allocated on the line items / shipping lines. This means it's indeed possible to have line_item.total_discount equal to 0, even if order.total_discount is not zero, as you mentioned.

Discount applications and their allocations include all discounts, not matter how they are presented (on the order or the line item). The discount application itself describes the discount calculation intention and type, so it's up to the client to decide how to present discounts given this information, if need be.

Also the API is backward compatible as we, more or less, always stored discounts this way internally, so all orders created before the discount allocations were introduced also expose those attributes.

Let me know if this helps!

0 Likes
Shopify Partner
660 0 104

Thanks Felix for the speedy response.

So if I understand correctly, for reporting purposes line_item.total_discount is totally useless right?

We can always use line_item.discount_allocations, instead, even on very old orders?

Also, I wanted to confirm that the following equation is always true:

order.total_discounts = sum of discount allocations of all line items and shipping lines

Correct?

In other words, the entire discount amount is always 100% allocated to line items and/or shipping lines. Which means that there is no need for us to ever manually allocate the order-level discount to line items (pro-rata) as it is already done by Shopify.

Sorry to drill in but I want to make sure I got this correctly.

0 Likes
Shopify Staff
Shopify Staff
16 0 0

For reporting purposes line_item.total_discount is totally useless right?

Yes, this is correct.

We can always use line_item.discount_allocations, instead, even on very old orders?

Yes, this is also correct.

Also, I wanted to confirm that the following equation is always true:

order.total_discounts = sum of discount allocations of all line items and shipping lines

Correct?

You got it right!

In other words, the entire discount amount is always 100% allocated to line items and/or shipping lines. Which means that there is no need for us to ever manually allocate the order-level discount to line items (pro-rata) as it is already done by Shopify.

Exactly, you get the exact allocation done by Shopify in the backend. 

Let me know if there is anything else!

0 Likes
Shopify Partner
660 0 104

Sweet, that's what I wanted to hear!

Thanks!

0 Likes
Shopify Partner
660 0 104

Hi Felix,

We have come accross an order for which the equation does not hold.

It's an order with two discount applications, but only one of the two is allocated.

We are concerned about this because this could mean our reporting is wrong.

Are you able to investigate what happened here?

The order in question is https://nitrocharts-testing.myshopify.com/admin/orders/387291185212

0 Likes
Shopify Staff
Shopify Staff
16 0 0

Hi Clement!

I will investigate further as it seems there is a problem with the data itself with this order, the discount across all line items was not allocated properly. The API returns the truth, which is concerning a bit.

I'll get back to you when I have more information.

Thanks for letting me know about this.

0 Likes
Shopify Partner
660 0 104

Ok.

We are almost ready to deploy our changes to incorporate discount allocations but we will wait until we hear back from you on this one.

If it's a freak order it may be ok but if it's a more widespread issue then we might hold off for now.

0 Likes
Shopify Staff
Shopify Staff
16 0 0

I understand. I am under the impression it's an outlier, but I'll have to confirm. I'll investigate this tomorrow morning as it is late a bit here (EDT) and I'll let you know.

0 Likes
Shopify Partner
660 0 104

Sure, thanks for the quick replies!

0 Likes