orderEditAddVariant and orderEditSetQuantity

Hi there, we’re using orderEditAddVariant to synchronise orders between an ERP system and the store, basically someone adds a line to the order on the ERP system it needs to also be added to the order on the store.

We’ve a couple of issues:

  1. When using orderEditSetQuantity to change the quantity the order doesn’t automatically recalculate the taxes - is there a way of forcing it or am I missing somthing?

  2. When using orderEditAddVariant taxes don’t recalculate and the price is set to the store price for that item - in order to handle price adjustments do we need to use orderEdit….Discount mutations?

Thanks

For the tax issue with orderEditSetQuantity, the taxes should recalculate when you commit the edit with orderEditCommit, not during the individual mutations themselves. The editing mutations stage changes in a “calculated order” and taxes get recalculated at commit time. If taxes are still wrong after committing, check that the store’s tax settings and the shipping address on the order are correct because Shopify calculates taxes based on destination (https://shopify.dev/docs/api/admin-graphql/current/mutations/orderEditCommit).

For the pricing on orderEditAddVariant, yeah it pulls the current store price by default. To set a custom price that matches your ERP, you need to apply an orderEditAddLineItemDiscount after adding the variant to adjust it down, or if the ERP price is higher you’d use orderEditAddLineItemDiscount with a negative approach which doesnt really work, so honestly the cleanest path for custom pricing is to use orderEditAddCustomItem instead of orderEditAddVariant since it lets you set the price directly. The tradeoff is you lose the variant association but you control the exact amount.

This is actually one of those cases where the order editing API gets really painful to maintain as a sync mechanism between an ERP and Shopify. Every edge case (taxes, discounts, custom prices, refunds) needs its own mutation chain and error handling. At Stacksync we handle this kind of ERP to Shopify order sync natively with two way real time sync that manages the field mapping and all these mutation quirks automatically, so you dont have to build and maintain the glue code for every scenario.

Hope that helps!

1 Like

Hey Ruben, thanks for you response - really helpful to know I’m not totally heading in the wrong direction!

I didn’t think to check the tax settings, but then looking at the code the initial order is created using the REST orders.json POST and we populate the tax lines ourselves there, I’ve now applied the UK tax in the store and adjusting quantities is adjusting the tax as it should - so that’s a great start, adding new lines also adjusts the tax so happy with that.

You’ve confirmed my suspicions on the pricing, I kind of guessed this would be the way but using orderEditAddCustomItem hadn’t occurred to me for increases - they’re just going to have to deal with that but I suspect occurrences will be rare.

Thanks again for you help - much appreciated.