Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
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:
https://shopify.dev/api/storefront/reference/products/productvariant
)
—> 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.
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:
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.
@Override
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.