View Categories

Can’t change quantity on Shopify free themes initially after adding to cart. You can only add this item in increments of

1 min read

If you are seeing the message “You can only add this item in increments of” when changing the quantity for an item just added to cart with the app, you need to make a small change to one of your script files in your Shopify theme.

Because the app creates new variants at runtime and Shopify takes some time to actually add that variant to the backend, some data is missing when items are first added to cart.

Shopify has recently added a conditional check when changing quantity that will fail when the variant is still being creating resulting in the message “You can only add this item in increments of”.

To resolve this issue:

  1. Go to Sales Channels > Online Store > … > Edit code

2. Search for cart.js

3. Edit cart.js

4. Search for the function validateQuantity

5. Edit the validateQuantity function as follows and add the element highlighted in bold red below.

 validateQuantity(event) {
    const inputValue = parseInt(event.target.value);
    const index = event.target.dataset.index;
    let message = '';

    if (inputValue < event.target.dataset.min) {
      message = window.quickOrderListStrings.min_error.replace('[min]', event.target.dataset.min);
    } else if (inputValue > parseInt(event.target.max)) {
      message = window.quickOrderListStrings.max_error.replace('[max]', event.target.max);
    } else if (  event.target.step !== "" && !isNaN(parseInt(event.target.step)) && inputValue % parseInt(event.target.step) !== 0) {
      message = window.quickOrderListStrings.step_error.replace('[step]', event.target.step);
    }

    if (message) {
      this.setValidity(event, index, message);
    } else {
      event.target.setCustomValidity('');
      event.target.reportValidity();
      this.updateQuantity(
        index,
        inputValue,
        document.activeElement.getAttribute('name'),
        event.target.dataset.quantityVariantId
      );
    }
  }


6. Save the script