Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hey guys, I am working on a cart and I am trying to determine if a max quantity is reached.
For example, when a customer clicks on the "Add to Cart" button, that one uses the add.js call, and if the user already has the max quantity in his cart, it returns a 422 status code, saying that max quantity is reached.
However, if the customer clicks on the + button in the cart to increase quantity, I am using the change.js call to increase (or decrease) the quantity, but once I reach the max quantity, it no longer increases, but it still returns status 200 as if everything is fine, and I have no way of detecting wether max quantity is reached with change.js. No way that I can find in the cart API documentation https://shopify.dev/docs/themes/ajax-api/reference/cart
So how do I determine wether a max quantity is reached with change.js?
I have just tried to do it with the update.js, and that is even allowing me to update the cart to quantities that are not available (for example, available quantity is 4, I got it up to 12!)! Still no errors.
I usually try to set the max attribute on the input to the variant inventory quantity, and then check the validate the value of the input against that max.
<input type="number" max="{{ item.variant.inventory_quantity }}">
Have you found solution?
We have discovered that this behavior is specific to some stores, and in some cases, only some cart items. We have Store A where going over the quantity available results in a 422 error, Store B where going over the available quantity results in a 200 error for all cart items, and Store C where we get a 422 error if we go over the available quantity only for the first item, but not for any subsequent items. 🙃
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025