Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I'm currently using the Storefront API to build a web shop and some of the products for sale are unique and others are not.
A painting, for example, has an inventory quantity of 1 and "Continue selling when out of stock" is not enabled.
A sticker has an inventory quantity of 1 (for the sake of example) and "Continue selling when out of stock" is enabled.
Whilst managing the adding and removal of items to and from the cart, I'd very much like to be able to prevent users from adding more than 1 painting, but allow them to add any amount of stickers. If the stickers had a quantity of 1, I'd be able to refer to the 'currentlyNotInStock' field on the ProductVariant, but as they are in stock, I have no way of knowing not to restrict the quantity in the cart.
I could do this based on the collection that the product is in or the tags that have been applied, but ideally I'd be able to read a 'sellWhenOutOfStock' field (or something similar) from the ProductVariant.
Is there a way to achieve this that I'm overlooking? If not, how do I go about requesting this feature?
There's a currentlyNotInStock boolean on the ProductVariant:
currentlyNotInStock (Boolean!)
Whether a product is out of stock but still available for purchase (used for backorders).
I'd assume you'd need to use this in combination with availableForSale and quantityAvailable:
availableForSale (Boolean!)
Indicates if the product variant is available for sale.quantityAvailable (Int)
The total sellable quantity of the variant for online sales channels.
There's an additional permission: unauthenticated_read_product_inventory access inventory. You'll need to configure this from your private app in order to get anything useful for quantityAvailable.
https://shopify.dev/docs/storefront-api/reference/products/productvariant#fields-2021-01
You may also want to still add additional tag, collection, product type or meta field to make the behaviour explicit opt in.