How to get out of stock status when updating cart using AJAX API /cart/change.js

6 0 3

I am creating a Shopify store using a theme. I've made customization in that according to my requirements. I want to to get out of stock status when we change products in cart using +/- icons. When we do add to cart then its showing out of stock item error but not on update.


In short when we call /cart/add.js then its providing out of stock error but not on /cart/change.js.


Any help? :)


Too late to the party but for future readers, you could generate the available stock in a data-attribute with liquid {{ item.variant.inventory_quantity }}

Something like :

<button type="button">−</button>
<input readonly name="updates[]" value="{{ item.quantity }}" min="0">
<button type="button" data-quantity-max="{{ item.variant.inventory_quantity }}">+</button>


And then use javascript on top of that. It's not updated in real time (since liquid is generated on page rendering), so keep this in mind. 

C'est simple comme bonjour ! Ou presque.