Can not use currentlyNotInStock field to properly validate conditions when shopper add item to cart

Shopify Partner
6 0 0

Hi there,

We are developing a mobile app which works as a sales-channel for Shopify store. (Currently we are using access token generated by private app created in the backend of the Shopify store).

In regards to validating stock-level to allow mobile users to add items to cart. (See product variant or simple product in:


—> We need to base on three fields that returned from Shopify API: isAvailableForSale, quantityAvailable and currentlyNotInStock.

After thorough research and performing relevant tests, I see that, in Shopify, the “currentlyNotInStock” field is used to support the back-order feature, and in the store backend, we can specify this by selecting the "Continue selling when out of stock" checkbox.

However, the value of currentlyNotInStock = true if and only if we have both necessary and sufficient conditions.

  • The necessary condition: The "Continue selling when out of stock" checkbox is selected in the backend.
  • The sufficient condition: The current inventory level of that product <=0. (Please note that, in the backend → merchant can enter negative number to this field)

And we faced a scenario in which we are unable to decide exactly and properly whether to allow app user add an item to cart based on values of above three fields. The scenario is:

  • The checkbox: “Continue selling when out of stock” is selected in the store backend (As mentioned above, this indicates that, the store supports back-order, is it right ?)
  • quantityAvailable == n >=0 (and with this value —> the currentlyNotInStock field will be false)
  • The quantity of the item that app user wants to add to cart is greater than n.

As you can see, with this scenario, since the “Continue selling when out of stock” is selected —> we should allow app user to add any quantity of the item to cart. However, the returned value of the currentlyNotInStock is false.

Therefore, we are do not know how to handle this scenario.

And following is our code to validate adding items to cart conditions.



  public void validateStock(CheckoutLineItem lineItem, int quantity, ReloadableResourceBundleMessageSource messageSource, Object... settings) throws ValidateStockException {

    ProductVariant variant = lineItem.getVariant();

    if (variant == null || !variant.isAvailableForSale()) {

      throw new ValidateStockException(

          ShopifyUtil.productSoldOut(lineItem.getTitle(), messageSource));





Thank you in advance and look forward to hearing from all of you.

Replies 0 (0)