CS-Cart allows you define a product’s Minimum Quantity and/or Maximum Quantity. Unfortunately, the cart logic has a rather narrow definition of these quantity rules.
For instance, a customer buying a shirt (min qty: 6) can only satisfy the minimum with 6 of a particular size. 3 of size Medium + 3 of size Large does not meet the requirement.
Likewise, if the same shirt has a Maximum Quantity of 12, the cart will allow the customer to buy 12 Smalls, 12 Mediums, etc. because it sees each variation as a unique product.
If you happen to be using the Product Configurator addon, you’ll notice that the Minimum/Maximum Quantities only apply to each Configured Product’s children - not across multiple Configured Products.
To correct this, we need to edit /core/fn.cart.php.
Find
```php
if ($amount < $min_qty) {
fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’] , $min_qty), fn_get_lang_var(‘text_cart_min_qty’)));
$amount = $min_qty;
} elseif (!empty($product[‘max_qty’]) && $amount > $product[‘max_qty’]) {
$amount = $product[‘max_qty’];
fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’], $product[‘max_qty’]), fn_get_lang_var(‘text_cart_max_qty’)));
```
And replace it with
```php
// START // Min Max Quantities with Options Mod
$max_qty = $product[‘max_qty’];
$new_amount = $amount;
foreach ($_SESSION[‘cart’][‘products’] as $k => $v) { //poll the cart contents for existing items
if (($v[‘product_id’] == $product_id) && ($k != $cart_id)) {
$new_amount += $v[‘amount’];
}
}
if (!empty($max_qty) && $new_amount > $max_qty) {
if ($new_amount > $amount) { //this item already exists in the cart
if (($new_amount - $amount) >= $max_qty) { //the existing item already hits the max qty
$amount = 0; //no more room for the new item
$min_qty = 0; //prevent the min_qty alert
fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’], $max_qty), fn_get_lang_var(‘text_cart_max_qty’)));
} else { //limit new item’s quantity
if ($new_amount > $max_qty) {
$amount = $max_qty - ($new_amount - $amount);
fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’], $max_qty), fn_get_lang_var(‘text_cart_max_qty’))); }
}
} else { //this is the only occurance of this item in the cart
if ($amount > $max_qty) {
$amount = $max_qty; //limit new item’s quantity
fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’], $max_qty), fn_get_lang_var(‘text_cart_max_qty’)));
}
}
}
if ($new_amount >= $min_qty) { //the existing item already hits the min qty
$min_qty = $amount;
}
if ($amount < $min_qty) {
fn_set_notification(‘W’, fn_get_lang_var(‘notice’), str_replace(array(‘[product]’ , ‘[quantity]’), array($product[‘product’] , $min_qty), fn_get_lang_var(‘text_cart_min_qty’)));
$_SESSION[‘notifications’] = fn_array_unique($_SESSION[‘notifications’]); //suppress duplicate error messages
if ($_REQUEST[‘dispatch’] == ‘checkout.checkout’) { //don’t allow checkout until min_qty satisfied
header(‘Location: index.php?dispatch=checkout.cart’);
}
// END // Min Max Quantities with Options Mod
```
Highlights of the new functionality:
- Minimum Quantity is satisfied with different product options or Configured Products
- customer is not forced to satisfy the Minimum Quantity until Proceed to Checkout
- Maximum Quantity limits are hit with different product options or Configured Products
Note: you may want to adjust the text_cart_max_qty and text_cart_min_qty language to better reflect the above functionality. This was done in CS-Cart 2.1.1 but I’ve also applied it to a 2.0.14 install.
cheers,
Glen