Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Discounts limitation in order REST API?

riorifai
Shopify Partner
1 0 0

Hello fellow devs! We are building an app that syncs the user's orders on our app. I am facing an issue with the order API when it comes to figuring out the line item discounts. Here is the issue I am facing:

 

1. Create an order with Product A as line item and quantity 3. Apply a discount on Product A (for example 10$). Making the total discount on product A 30$.

 

2. Edit the order and adjust the quantity of Product A to 2 instead of 3.

 

3. Call the Orders API.

 

The issue: The discount for line item Product A is still returning 30$ instead of 20 (since it should be 10 per item, and I had adjusted the quantity to 2). 

When I access 'total_discount' field in the line_items array in the order, it returns the wrong/old value (30). If I access the 'discount_allocations' field in line_items, it also still has the old value.

 

If I access the deleted line item from 'refunds' array in the order, then I get the 'subtotal' from the 'refund_line_items', the subtotal is returning a value that I am unable to figure out how shopify got it, it's neither the original item price nor its price after discount. And in both cases, there is nothing related to discounts.

 

And if I try to access 'discount_applications', there is nothing that links the discount application to the product id/line item id, so I'm unable to get the value of the discount that I'm supposed to remove from the 30 (which is 10 in this example's case).

 

What I need: A way to get the actual discounts applied on the line item with the correct new quantity. How are we supposed to get it? Is there something I'm missing?

 

 

Replies 0 (0)