API Suggestion: Add `options.inventoryBehaviour` to `draftOrderComplete`

Can you please add inventoryBehaviour todraftOrderComplete?
The last time I checked these APIs were not respecting continue selling when out of stock deselected in the product.

Hey @madfcat, assuming you’re exploring draft orders as an alternative to orderCreate (as per the other thread)?

Draft orders will decrement automatically when the order is complete. The general advice when working with draft orders is to validate inventory first.

For example, the same is possible in the admin when creating draft orders for items out of stock, but there will be a small warning:

For context, the reason orderCreate has this option as that endpoint is typically for creating records of an order already completed, so most cases the inventory shouldn’t be adjusted; whereas draft orders are for merchants to create manual orders for merchants to later purchase or complete.

Just to confirm my understanding: it is impossible to not oversell with completing draft orders?

From my understanding:

Checking the inventory and completing a draft order will lead to a race condition between instances of the same app when scaling horizontally + other sales channels in the Shopify itself will also will participate in this “race”.

Longer-term, it seems to be beneficial if the transactions and the stock checks were implemented in Shopify APIs itself not allowing to oversell or respecting the inventoryBehaviouroption.

That is true, however you can prevent overselling if you use reserveInventoryUntil when you create the draft order, that inventory won’t be available to be purchased on another non-draft order.

Good point but not exactly what I am looking for :ok_hand:

Is there a way to have no overselling between draft orders? Seems pretty straight forward for orderCreate, not for draftOrderCreate + draftOrderComplete.

I think the tricky part is that inventory handling with draft orders works differently from a normal order creation flow. Have you tried reserving the inventory when the draft order is created, then releasing it if the draft order expires or gets cancelled? That might help prevent two draft orders from competing for the same stock !!!

No. It does not work the way you think even with reserveInventoryUntil. I need draft orders not getting completed if out of stock and use the right stock if it is available in other country.

At the moment, the available stock will not get prioritized. Let’s say I have no stock in Brazil warehouse and some stock in US warehouse. Creating an order with Brazil as a delivery address will use 0 stock (from Brazil warehouse) and go negative instead of using US stock which has, for example, 20 items in stock (Order routing not working). :woman_facepalming:

I am not even starting to rant about split orders which of course does not work as well. Just the stock goes negative. :woman_shrugging: