# Shopping cart: restrict order qty / grey out minus sign

Go to solution Solved by premiumpresta,

## Recommended Posts

Goodmorning everybody,

We sell some of our products with an Minimal Order Quantity (MOQ).

For example, item X has a MOQ of 12. So when somebody wants to buy item X, we

1) need Prestashop to show at default the MOQ quantity (i.e. 12 in this example) and have the minus sign greyed out (because quantities < 12 cannot be ordered).

and we also

2) need Prestashop to restrict the quantity that can be ordered to 12 or quantities that follow the formula: quantity = 12 + n*12  (n being integers of 0 or higher)...OR put in a different way: higher amounts that are only within the mathematic table of 12 (...24, 36, 48...etc.).

Does anyone here know of such a functionality / add-on or have pointers that would get us nearer to a solution for our problem?

Many thanks in advance for any help,

Best regards,

Redmar

Edited by redmar (see edit history)

##### Share on other sites

I will assume that you use the version 1.6.1.5 with the default theme.

If I understand correctly, you want to always calculate the quantity as n*MOQ (where n is altered by - and + buttons).

Start by showing the MOQ under product attributes, edit file shopping-cart-product-line.tpl and under line 34 add:

```<strong class="minimal-quantity" data-value="{\$product.minimal_quantity}">{l s='MOQ'}: {\$product.minimal_quantity} {l s='pcs'}</strong>
```

You may also want to make the quantity input so the user can't type any value. At line 96 add attribute readonly.

To change the quantity adjustment behavior, edit the file cart-summary.js.

Change line 581 into:

```qty = parseInt(\$('#product_' + id + ' .minimal-quantity').data('value'));
```

Change lines 684, 685 into:

```qty = parseInt(\$('#product_' + id + ' .minimal-quantity').data('value'));
newVal -= qty;
```

To disable the - button when the quantity equals MOQ, under line 877 add:

```if (\$('input[name=quantity_' + key_for_blockcart_nocustom + ']').val() <= \$('#product_' + key_for_blockcart_nocustom + ' .minimal-quantity').data('value')) {
} else {
\$('#cart_quantity_down_' + key_for_blockcart_nocustom).removeClass('disabled');
}
```

##### Share on other sites

we implemented the code provided by you, after saving cart-summary.js and refreshing testing starts ;-)

After adding product to cart from product page, the quantity is 6 pieces as defined on product level.

I added console trace to both up-and downQuantity.

When i press +, i get error message popup telling me there is no quantity and in the console i see the log value NaN.

console.log(parseInt(\$('#product_' + id + ' .minimal-quantity').data('value')));

Best regards,

Richard

##### Share on other sites

The first edit in shopping-cart-product-line.tpl is essential for the code in cart-summary.js because it adds data-value of minimal quantity. So make sure you haven't missed that.

Also make sure you clear the smarty cache after editing the files.

##### Share on other sites

Okay, works now ;-)

Only sometimes i can not find out in which specific situation, i get error message popup only in case of pressing + button.

->> TECHNICAL ERROR: unable to save update quantity Details: Error thrown: [object Object] Text status: error

Can this same code change be applied to to + and - sign on the product detail page?

Edited by RiesjardVV (see edit history)

##### Share on other sites
• 2 weeks later...

For the product page is a little bit trickier, but it can be adapted on the same principles.

If you provide your link I can look into why you get that error when pressing + button.

##### Share on other sites

error does not occur anymore, i think it was a cache related issue.

Can u giver me an ocerview of code changes in order to makes +/- sign also work on product page?

##### Share on other sites

Here's how you can get the same behavior on the product page.

```if (typeof minimalQuantity !== 'number' || minimalQuantity < 1) {
minimalQuantity = 1;
}
checkMinimalQuantity(minimalQuantity);```

Replace line 358 with:

```\$('input[name='+fieldName+']').val(currentVal + minimalQuantity).trigger('keyup');
```

Replace line 370 with:

```\$('input[name='+fieldName+']').val(currentVal - minimalQuantity).trigger('keyup');
```

At the end of function checkMinimalQuantity() add:

```if (\$('#quantity_wanted').val() <= minimal_quantity)
{
} else {
\$('#quantity_wanted_p .product_quantity_down').removeClass('disabled');
}
```
Edited by premiumpresta (see edit history)

##### Share on other sites

Thks works like a charm,

Only open point is disabling the qnty field so customer can only use + and -.

Grtz RIchard

##### Share on other sites
• Solution

You can make the quantity field readonly like you did on shopping-cart-product-line.tpl.

This thread can be marked as solved now

##### Share on other sites

Thks for support, i will ask Redmar to close the thread ;-)

##### Share on other sites

On behalf of Richard and me a big thank you for your detailed help!!!

Have a great day, with very kind regards,

redmar

## Create an account

Register a new account