1

I'm trying to set a max amount on the quantity in the cart. My problem is I want a customer to be able to update their quantity while in the cart, but I can't seem to figure out how to set the max quantity according to the stock on hand. I've done this with variant.stock in the items page, but can't seem to find anything that allows me to pull that information according to the lineItem in the cart page.

2

Assuming your lineItem variable is called item, you're looking for

item.purchasable.stock

You might also need to pay attention to maxQty which is the maximum number of a purchasable item that a user is allowed to buy. I limit customers to a maximum of 10 and create a select box on the basket form with a Remove option at the bottom:

{% set maxQuantity = item.purchasable.stock > 10 ? 10 : item.purchasable.stock %}
{% if item.purchasable.maxQty %}
    {% set maxQuantity = maxQuantity > item.purchasable.maxQty ? item.purchasable.maxQty : maxQuantity %}
{% endif %}

<select name="qty">
    {% for i in 1..maxQuantity %}
        <option value="{{ i }}" {{ i == item.qty ? 'selected' }}>{{ i }}</option>
    {% endfor %}
    <option value="0">Remove</option>
</select>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.