How can I limit product quantity in the Impulse theme?

Topic summary

Limiting product quantity to available stock in the Impulse theme. Goal: set the quantity selector’s maximum to the selected variant’s inventory.

Initial approach: add an HTML max attribute bound to inventory in quantity-input.liquid for single-variant products. For multi-variant products, JS changes are required to enforce the limit.

Proposed JS edits in theme.min.js: read max from the input and clamp quantity changes. Early edits caused issues (images not loading, quantity stuck at 1); corrected code snippets were provided, but the limit still didn’t apply consistently.

Next steps offered: remote debugging and rewriting, noting the quantity function is used in multiple places. The store decided to handle the work in-house.

Alternative solutions: apps suggested to manage purchase limits globally (Purchase Limit, Limit Sales Per Day, Limit Quantity Purchase), including features for min/max per product and collections.

Latest update: a practical fix shared—insert max=“{{ product.selected_or_first_available_variant.inventory_quantity }}” in main-product.liquid around line ~284. A screenshot was provided and is central to implementation.

Status: partially resolved via Liquid for max setting; robust multi-variant JS enforcement may still require further development.

Summarized with AI on February 4. AI used: gpt-5.

Hi @SunShopp ,

Sorry, quantity is still changing in JS, so you need to change more code in theme.min.js file.
Go to Assets > theme.min.js , find ‘.js-qty__adjust–minus’ and add code here:
https://i.imgur.com/kSNaywk.png , Code: this.maxValue = this.input.getAttribute(“max”) || 1
Find ‘this._change(this._getQty())’ and change code:

this._change(this._getQty())
=>
var e = this._getQty();
if (e >= this.maxValue) {
  e = this.maxValue;
}
this._change(e);

Refer https://i.imgur.com/iuTVt0w.png
Hope it helps!

1 Like