Why is the exported data still showing the original values after editing an order and removing a line item or decreasing the quantity?

When you edit an order via the Shopify Admin and remove a line item or decrease the quantity, you'll notice that the order export still shows the original values.  You'll see the same behavior in Shopify's CSV export as well.

What happens on the Shopify backend is they instead "refund" these line items (though the payment status doesn't change to "partially refunded" probably because no payment was actually refunded).

In EZ Exporter, there's a field called line_items.refunded_quantity that you can include in the report to identify them and perhaps use a Calculated Field with this formula to export the actual ordered quantity:

{{ line_items.quantity }} - {{ line_items.refunded_quantity }}

There's also a field called line_items.fulfillable_quantity which already takes the refunded quantity into account. So if you're only exporting unfulfilled orders, you might want to use this field instead of the line_items.quantity field to get the actual quantity that needs to be fulfilled.

The other issue is the total_price field is also not adjusted.  Since there's no actual transaction, the refund transaction data is empty in the Shopify API. But there's another field called "refund_line_items" that has the subtotal and tax for the line items that were removed which we can use to calculate the current total price after editing the order.

{{ total_price }} - get_total(get_attribute_value(get_attribute_value({{ refunds }}, "refund_line_items", return_raw_results=True), "subtotal", return_raw_results=True)) - get_total(get_attribute_value(get_attribute_value({{ refunds }}, "refund_line_items", return_raw_results=True), "total_tax", return_raw_results=True))

The formula is quite complicated due to the way the refunds data is structured.  But what this basically does it go through the refund_line_items fields, pull out the subtotal value, add them up, then subtract them from the original total price.

Related post from the Shpopify forums: https://community.shopify.com/c/Shopify-APIs-SDKs/API-is-serving-deleted-removed-order-line-items/m-p/716942


App: EZ Exporter

Tags: shopify order editing