GraphQL Storefront Inventory Quantity

Solved
fff_www
Shopify Partner
16 0 7

Dear All,

 

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...

 

Bildschirmfoto 2020-05-29 um 17.14.51.jpgBildschirmfoto 2020-05-29 um 17.06.58.jpg


Please compare these screenshots.

Any solution to this? How do you solve it?

https://shopify.dev/docs/storefront-api/reference/object/productvariant?api[version]=2020-04#fields-...

Do you use »availableForSale«, or do you use »quantityAvailable« with »unauthenticated_read_product_inventory«?

 

Thanks!

0 Likes
_JB
Shopify Staff
Shopify Staff
792 93 174

Hey @fff_www,

 

Can you please provide the shop_id or myshopify URL for the store you're seeing this behaviour on?

JB | 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
fff_www
Shopify Partner
16 0 7

@_JB pm.

0 Likes
_JB
Shopify Staff
Shopify Staff
792 93 174

This is an accepted solution.

Hey @fff_www,

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.

JB | 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