Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I use React-Hydrogen. The cart it fetches and exposes via the useCart hook doesn't contain the available quantity for the variants of a product. When I try to update the line item via
Unfortunately, the Shopify Storefront API doesn provide a direct way to get the available quantity of a product variant, so you'll likely need to use the Admin API to handle this separately.
An example approach could be:
Keep track of the requested quantity in your own app using the admin API Inventory Item object.
When you get the response from the linesUpdate
mutation, compare the new quantity with the requested quantity.
If the quantity in a cart is greater than the current quantity of the product, show an error message to the user indicating that the requested quantity isn't available.
Would this approach work?
Liam | Developer Advocate @ 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
Are you sure about this? When I fetch a product directly from the Storefront API, I can get quantityAvailable and availableForSale.
@Liam wrote:Unfortunately, the Shopify Storefront API doesn provide a direct way to get the available quantity of a product variant, so you'll likely need to use the Admin API to handle this separately.
I can confirm this from my side. If you ever find a workaround, please reply 🙂