linuxguy2:
Here is the newly generated shopping_cart class method to support this plugin... I haven't tested it, but the code looks right The two modifications are commented:
Code:
/**
* Method to handle cart Action - multiple add products
*
* @param string forward destination
* @param url parameters
* @todo change while loop to a foreach
*/
function actionMultipleAddProduct($goto, $parameters) {
global $messageStack;
if ($this->display_debug_messages) $messageStack->add_session('header', 'FUNCTION ' . __FUNCTION__, 'caution');
$addCount = 0;
if (is_array($_POST['products_id']) && sizeof($_POST['products_id']) > 0) {
// Begin mc12345678 Checkbox/TextBox 1 of 2
if ($_POST['check_text_active'] == true) {
$multiAddCheck = true;
} else {
$multiAddCheck = false;
}
// End mc12345678 Checkbox/TextBox 1 of 2
//echo '<pre>'; echo var_dump($_POST['products_id']); echo '</pre>';
$products_list = $_POST['products_id'];
foreach($products_list as $key => $val) {
$prodId = preg_replace('/[^0-9a-f:.]/', '', $key);
// Begin mc12345678 Checkbox/TextBox 2 of 2
if (
(
defined('PRODUCT_ALL_CHECKBOX_TEXTBOX_ACTIVE') && PRODUCT_ALL_CHECKBOX_TEXTBOX_ACTIVE == '1'
|| defined('PRODUCT_FEATURED_CHECKBOX_TEXTBOX_ACTIVE') && PRODUCT_FEATURED_CHECKBOX_TEXTBOX_ACTIVE == '1'
|| defined('PRODUCT_NEW_CHECKBOX_TEXTBOX_ACTIVE') && PRODUCT_NEW_CHECKBOX_TEXTBOX_ACTIVE == '1'
|| defined('PRODUCT_LISTING_CHECKBOX_TEXTBOX_ACTIVE') && PRODUCT_LISTING_CHECKBOX_TEXTBOX_ACTIVE == '1'
)
&& $multiAddCheck == true
) {
foreach($_POST['products_id2'] as $key2 => $val2) {
if ($key == $key2) {
if (is_numeric($val) && $val > 0)
{
$adjust_max = false;
$qty = $val;
$add_max = zen_get_products_quantity_order_max($prodId);
$cart_qty = $this->in_cart_mixed($prodId);
$new_qty = $this->adjust_quantity($qty, $prodId, 'shopping_cart');
if (($add_max == 1 and $cart_qty == 1)) {
// do not add
$adjust_max= 'true';
} else {
// adjust quantity if needed
if ((($new_qty + $cart_qty > $add_max) and $add_max != 0)) {
$adjust_max= 'true';
$new_qty = $add_max - $cart_qty;
}
$this->add_cart($prodId, $this->get_quantity($prodId)+($new_qty));
$addCount++;
}
if ($adjust_max == 'true') {
if ($this->display_debug_messages) $messageStack->add_session('header', 'FUNCTION ' . __FUNCTION__ . '<br>' . ERROR_MAXIMUM_QTY . zen_get_products_name($prodId), 'caution');
$messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . zen_get_products_name($prodId), 'caution');
}
}
break; /*Add product, otherwise don't add */
}
}
} elseif (is_numeric($val) && $val > 0) {
// End mc12345678 Checkbox/TextBox 2 of 2
$adjust_max = false;
$qty = $val;
$add_max = zen_get_products_quantity_order_max($prodId);
$cart_qty = $this->in_cart_mixed($prodId);
$new_qty = $this->adjust_quantity($qty, $prodId, 'shopping_cart');
// bof: adjust new quantity to be same as current in stock
$chk_current_qty = zen_get_products_stock($prodId);
if (STOCK_ALLOW_CHECKOUT == 'false' && ($new_qty > $chk_current_qty)) {
$new_qty = $chk_current_qty;
$messageStack->add_session('shopping_cart', ($this->display_debug_messages ? 'FUNCTION ' . __FUNCTION__ . ': ' : '') . WARNING_PRODUCT_QUANTITY_ADJUSTED . zen_get_products_name($prodId), 'caution');
}
// eof: adjust new quantity to be same as current in stock
if (($add_max == 1 and $cart_qty == 1)) {
// do not add
$adjust_max= 'true';
} else {
// bof: adjust new quantity to be same as current in stock
if (STOCK_ALLOW_CHECKOUT == 'false' && ($new_qty + $cart_qty > $chk_current_qty)) {
$adjust_new_qty = 'true';
$alter_qty = $chk_current_qty - $cart_qty;
$new_qty = ($alter_qty > 0 ? $alter_qty : 0);
$messageStack->add_session('shopping_cart', ($this->display_debug_messages ? 'FUNCTION ' . __FUNCTION__ . ': ' : '') . WARNING_PRODUCT_QUANTITY_ADJUSTED . zen_get_products_name($prodId), 'caution');
}
// eof: adjust new quantity to be same as current in stock
// adjust quantity if needed
if ((($new_qty + $cart_qty > $add_max) and $add_max != 0)) {
$adjust_max= 'true';
$new_qty = $add_max - $cart_qty;
}
$this->add_cart($prodId, $this->get_quantity($prodId)+($new_qty));
$addCount++;
}
if ($adjust_max == 'true') {
if ($this->display_debug_messages) $messageStack->add_session('header', 'FUNCTION ' . __FUNCTION__ . '<br>' . ERROR_MAXIMUM_QTY . zen_get_products_name($prodId), 'caution');
$messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . zen_get_products_name($prodId), 'caution');
}
}
if (!is_numeric($val) || $val < 0) {
// adjust quantity when not a value
$chk_link = '<a href="' . zen_href_link(zen_get_info_page($prodId), 'cPath=' . (zen_get_generated_category_path_rev(zen_get_products_category_id($prodId))) . '&products_id=' . $prodId) . '">' . zen_get_products_name($prodId) . '</a>';
$messageStack->add_session('header', ERROR_CORRECTIONS_HEADING . ERROR_PRODUCT_QUANTITY_UNITS_SHOPPING_CART . $chk_link . ' ' . PRODUCTS_ORDER_QTY_TEXT . zen_output_string_protected($val), 'caution');
$val = 0;
}
}
// display message if all is good and not on shopping_cart page
if (($addCount && DISPLAY_CART == 'false' && $_GET['main_page'] != FILENAME_SHOPPING_CART) && $messageStack->size('shopping_cart') == 0) {
$messageStack->add_session('header', ($this->display_debug_messages ? 'FUNCTION ' . __FUNCTION__ . ': ' : '') . SUCCESS_ADDED_TO_CART_PRODUCTS, 'success');
} else {
if (DISPLAY_CART == 'false') {
zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
}
}
zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
}
}
Bookmarks