There is a ... umm ... bug ... 
You can try this fix, but be careful with it ...
What this will do is when there is a Maximum of 5 and you have 3 in the amount on the shopping cart, and try to change it to 7, it will change back to 3 with a warning ...
If you try to add more from the product _info page, it will set the quantity to 5, with a warning ...
Backup your original shopping cart class file first, then try to edit the file:
/includes/classes/shopping_cart.php
and change lines 1121 - 1134 to read:
Code:
// validate cart contents for checkout
if ($check_for_valid_cart == true) {
$fix_once = 0;
// Check products_status if not already
$check_status = $products->fields['products_status'];
if ( $check_status == 0 ) {
$fix_once ++;
$_SESSION['valid_to_checkout'] = false;
$_SESSION['cart_errors'] .= ERROR_PRODUCT . $products->fields['products_name'] . ERROR_PRODUCT_STATUS_SHOPPING_CART . '<br />';
$this->remove($products_id);
} else {
if (isset($this->contents[$products_id]['attributes'])) {
reset($this->contents[$products_id]['attributes']);
$chkcount = 0;
while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
$chkcount ++;
$chk_attributes_exist_query = "select products_id
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
where pa.products_id = '" . (int)$products_id . "'
and pa.options_values_id = '" . (int)$value . "'";
$chk_attributes_exist = $db->Execute($chk_attributes_exist_query);
//echo 'what is it: ' . ' : ' . $products_id . ' - ' . $value . ' records: ' . $chk_attributes_exist->RecordCount() . ' vs ' . print_r($this->contents[$products_id]) . '<br>';
if ($chk_attributes_exist->EOF) {
$fix_once ++;
$_SESSION['valid_to_checkout'] = false;
$_SESSION['cart_errors'] .= ERROR_PRODUCT_ATTRIBUTES . $products->fields['products_name'] . ERROR_PRODUCT_STATUS_SHOPPING_CART_ATTRIBUTES . '<br />';
$this->remove($products_id);
break;
}
}
}
}
// check only if valid products_status
Changes lines 1394 - 1424 to read:
Code:
function in_cart_mixed($products_id) {
global $db;
// if nothing is in cart return 0
if (!is_array($this->contents)) return 0;
// check if mixed is on
// $product = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id='" . (int)$products_id . "' limit 1");
$product = $db->Execute("select products_id, products_quantity_mixed from " . TABLE_PRODUCTS . " where products_id='" . zen_get_prid($products_id) . "' limit 1");
// if mixed attributes is off return qty for current attribute selection
if ($product->fields['products_quantity_mixed'] == '0') {
return $this->get_quantity($products_id);
}
// compute total quantity regardless of attributes
$in_cart_mixed_qty = 0;
$chk_products_id= zen_get_prid($products_id);
// added for new code - Ajeh
global $cart, $messageStack;
// reset($this->contents); // breaks cart
$check_contents = $this->contents;
reset($check_contents);
while (list($products_id, ) = each($check_contents)) {
$test_id = zen_get_prid($products_id);
//$messageStack->add_session('header', 'Product: ' . $products_id . ' test_id: ' . $test_id . '<br>', 'error');
if ($test_id == $chk_products_id) {
//$messageStack->add_session('header', 'MIXED: ' . $products_id . ' test_id: ' . $test_id . ' qty:' . $check_contents[$products_id]['qty'] . ' in_cart_mixed_qty: ' . $in_cart_mixed_qty . '<br><br>', 'error');
$in_cart_mixed_qty += $check_contents[$products_id]['qty'];
}
}
//$messageStack->add_session('header', 'FINAL: in_cart_mixed_qty: ' . 'PRODUCT: ' . $test_id . ' in cart:' . $in_cart_mixed_qty . '<br><br>', 'error');
return $in_cart_mixed_qty;
}
/**
* Method to calculate item quantity, bounded the mixed/min units settings
Change lines 1532 - 1581 to read:
Code:
function actionUpdateProduct($goto, $parameters) {
global $messageStack;
for ($i=0, $n=sizeof($_POST['products_id']); $i<$n; $i++) {
$adjust_max= 'false';
if ($_POST['cart_quantity'][$i] == '') {
$_POST['cart_quantity'][$i] = 0;
}
if (!is_numeric($_POST['cart_quantity'][$i]) || $_POST['cart_quantity'][$i] < 0) {
$messageStack->add_session('header', ERROR_CORRECTIONS_HEADING . ERROR_PRODUCT_QUANTITY_UNITS_SHOPPING_CART . zen_get_products_name($_POST['products_id'][$i]) . ' ' . PRODUCTS_ORDER_QTY_TEXT . zen_output_string_protected($_POST['cart_quantity'][$i]), 'error');
continue;
}
if ( in_array($_POST['products_id'][$i], (is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array())) or $_POST['cart_quantity'][$i]==0) {
$this->remove($_POST['products_id'][$i]);
} else {
$add_max = zen_get_products_quantity_order_max($_POST['products_id'][$i]); // maximum allowed
$cart_qty = $this->in_cart_mixed($_POST['products_id'][$i]); // total currently in cart
//$messageStack->add_session('header', 'actionUpdateProduct Products_id: ' . $_POST['products_id'] . ' qty: ' . $cart_qty . ' <br>', 'caution');
$new_qty = $_POST['cart_quantity'][$i]; // new quantity
$current_qty = $this->get_quantity($_POST['products_id'][$i]); // how many currently in cart for attribute
$chk_mixed = zen_get_products_quantity_mixed($_POST['products_id'][$i]); // use mixed
//echo 'I SEE actionUpdateProduct: ' . $_POST['products_id'] . ' ' . $_POST['products_id'][$i] . '<br>';
$new_qty = $this->adjust_quantity($new_qty, $_POST['products_id'][$i], 'shopping_cart');
//die('I see Update Cart: ' . $_POST['products_id'][$i] . ' add qty: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty);
if (($add_max == 1 and $cart_qty == 1) && $new_qty != $cart_qty) {
// do not add
$adjust_max= 'true';
} else {
if ($add_max != 0) {
//$messageStack->add_session('shopping_cart', 'PROCESSING MAX: Update Cart chk_mixed false: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty . ' current_quantity: ' . $current_qty, 'warning');
// adjust quantity if needed
// if ($add_max != 0 && $new_qty > $current_qty && ($cart_quantity - $current_qty + $new_qty) != 0 && (($cart_quantity - $current_qty + $new_qty) + $cart_qty > $add_max)) {
switch (true) {
case ($new_qty == $current_qty): // no change
//$messageStack->add_session('shopping_cart', 'I see NEW=CURRENT Update Cart chk_mixed false: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty . ' current_quantity: ' . $current_qty, 'warning');
$adjust_max= 'false';
$new_qty = $current_qty;
break;
case ($new_qty > $add_max && $chk_mixed == false):
//$messageStack->add_session('shopping_cart', 'I see Update Cart chk_mixed false: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' - newqty: ' . $new_qty . ' something: ' . $something_qty, 'warning');
$adjust_max= 'true';
$new_qty = $add_max ;
break;
case (($add_max - $cart_qty + $new_qty >= $add_max) && $new_qty > $add_max && $chk_mixed == true):
//$messageStack->add_session('shopping_cart', 'I see NEW > ADD Update Cart chk_mixed true: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' + newqty: ' . $new_qty, 'warning');
$adjust_max= 'true';
$requested_qty = $new_qty;
$new_qty = $current_qty;
break;
case (($cart_qty + $new_qty - $current_qty > $add_max) && $chk_mixed == true):
//$messageStack->add_session('shopping_cart', 'I see CART + NEW - CURRENT > ADD Update Cart chk_mixed true: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' + newqty: ' . $new_qty . ' current_qty: ' . $current_qty, 'warning');
$adjust_max= 'true';
$requested_qty = $new_qty;
$new_qty = $current_qty;
break;
default:
//$messageStack->add_session('shopping_cart', 'I see DEFAULT Cart - TURN OFF<br>: ' . $_POST['products_id'][$i] . ' add max: ' . $add_max . ' - cart qty: ' . $cart_qty . ' + newqty: ' . $new_qty . '<br>' . 'current: ' . $current_qty, 'warning');
$adjust_max= 'false';
}
$attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';
$this->add_cart($_POST['products_id'][$i], $new_qty, $attributes, false);
} else {
// adjust minimum and units
$attributes = ($_POST['id'][$_POST['products_id'][$i]]) ? $_POST['id'][$_POST['products_id'][$i]] : '';
$this->add_cart($_POST['products_id'][$i], $new_qty, $attributes, false);
}
}
if ($adjust_max == 'true') {
// $messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . ' A: - ' . zen_get_products_name($_POST['products_id'][$i]), 'caution');
//$messageStack->add_session('shopping_cart', 'actionUpdateProduct<br>' . ERROR_MAXIMUM_QTY . zen_get_products_name($_POST['products_id'][$i]) . '<br>Requested: ' . $requested_qty . ' current: ' . $current_qty , 'caution');
$messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . zen_get_products_name($_POST['products_id'][$i]), 'caution');
} else {
// display message if all is good and not on shopping_cart page
if (DISPLAY_CART == 'false' && $_GET['main_page'] != FILENAME_SHOPPING_CART) {
$messageStack->add_session('header', SUCCESS_ADDED_TO_CART_PRODUCT, 'success');
}
}
}
}
zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
}
/**
* Method to handle cart Action - add product
Bookmarks