"currentlyNotInStock" field on product variant is always returning "false" even when quantity is "0"

tedisawesome
New Member
3 0 0

Hi,

 

So we currently have a headless commerce site setup leveraging the JS Buy SDK and Storefront APIs so we can manage the cart experience on our own custom website.

 

We want to add in UI to display product variants that are out of stock and in the latest release of the Storefront API, we saw that there is a `currentlyNotInStock` field on the product variant.

 

However, when setting the quantity of the variant to 0 and making Shopify the inventory tracking manager, currentlyNotInStock is always returning as false instead of true as what I would expect since it's out of stock.

 

We have the products available in our custom Shopify private app which is not a sales channel. How is this currentlyNotInStock field getting set?

Replies 4 (4)
_JB
Shopify Staff
834 99 190

Hey @tedisawesome,

 

Thanks for bringing this up, I've tested on my end as well and it seems this field always returns false regardless of the actual state of inventory. I'll be raising this with our developers to clarify the expected behaviour and get a fix in place if necessary, I'll post back here with an update as soon as I have it.

 

In the meantime, you can consider using quantityAvailable which returns the actual number of units in stock. If you don't see this field, make sure your API client has the  unauthenticated_read_product_inventory permission.

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

tedisawesome
New Member
3 0 0

Thanks @_JB !

 

Yeah I ended up using the `availableForSale` flag which does track the inventory quantity and does send back the correct value, BUT the products have to be enabled in the Shopify Online Store also. They don't work by default for the private apps we created for our headless commerce website.

 

Yeah let me know about the `currentlyNotInStock` as the verbiage of this field makes more sense than `availableForSale` as this has a bit different meaning.

psongpin
New Member
2 0 0

Any updates on this? I'm getting the same issue with this. availableForSale seems to serve the purpose. can't use quantityAvailable field because some of our products' inventory are not tracked by shopify

CalD
Shopify Staff
140 21 29

Replying for future reference - this is intended behaviour that may have not been worded clearly enough at the time last year.

availableForSale will return false if no inventory is available for that variant.

currentlyNotInStock will return true only if the variant inventory quantity is <= 0 and overselling is allowed.

The ProductVariant docs were updated with descriptions that hopefully make this clearer:

Screen Shot 2021-08-16 at 1.20.23 PM.png

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