How are "discount codes" applied when editing orders

Solved
longinoa
Excursionist
15 1 0

I am testing editing my order to replace the product that is being shipped.

 

My basic flow is

create an order in the test shop - set a discount code for $500 off the order

process the order in my nodejs to do the following:

orderEditBegin

orderEditSetQuantity of the item I want to remove (setting quantity to 0)

orderEditAddVariant adding the replacement product (which costs the same amount)

orderEditCommit

 

The problem comes in that the resulting calculatedOrder has a non zero totalOutstandingSet. In my original order I get:

"originalOrder":{"discountApplications":{"edges":[{"node":{"allocationMethod":"ACROSS","index":0,"targetSelection":"ALL","targetType":"LINE_ITEM","value":{"__typename":"MoneyV2","amount":"500.0"}}}]}

 

Do I need to re-add the discountApplications?

0 Likes
_JCC_
Shopify Staff
Shopify Staff
66 10 9

This is an accepted solution.

Hey @longinoa ,

Happy to help you out with this. Yes, after adding the new line item and assuming the new line item added gets the same discount you would need to add it using orderEditAddLineItemDiscount before your commit.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes