My initial question is on how to prevent the customer to add a product to the checkout which quantity is not available any more. Lets say we have 5 t-shirts available and the customer clicks 6-times add-to-cart.
The answer a Shopify Staff gave me was this:
With the Storefront API, an error will be thrown if you try to create a checkout with a quantity of product variants greater than what is currently in inventory. So Shopify/Storefront API will prevent users from ordering too many, you do not need to do anything on your end.
And further, this was said before »unauthenticated_read_product_inventory« was introduced:
You cannot obtain the quantity levels of a product variant from the Storefront API. You can only check if it is `availableForSale` , which will return true if there is 1 or more available quantities of that product variant remaining
But this is actually not true, because I can add more products to a checkout than available.
This is the quantity within Shopify & the checkout I can make from it. What you see is that I can add more than 1 item to the checkout, which supposed to not work, as Shopify Staff said...
Please compare these screenshots.
Any solution to this? How do you solve it?
Do you use »availableForSale«, or do you use »quantityAvailable« with »unauthenticated_read_product_inventory«?
Solved! Go to the solution
Can you please provide the shop_id or myshopify URL for the store you're seeing this behaviour on?
This is an accepted solution.
I got some clarification around the expected behaviour here, and I can confirm that the behaviour you describe is expected. The storefront API will allow creation of a checkout regardless of the quantity used, and during checkout an inventory error will appear if the products aren't available. You can use the
quantityAvailable field to do a check to determine if a product can be added to a checkout.