/** * Method to update a cart items quantity * * Changes the current quantity of a certain item in the cart to * a new value. Also updates the database stored cart if customer is * logged in. * * @param mixed product ID of item to update * @param decimal the quantity to update the item to * @param array product atributes attached to the item * @return void */ public function update_quantity($products_id, $quantity = '', $attributes = '') { $this->notify('NOTIFIER_CART_UPDATE_QUANTITY_START'); if (empty($quantity)) { return true; } // nothing needs to be updated if theres no quantity, so we return true.. $this->contents[$products_id] = array('qty' => (double) $quantity); // update database if ($this->getSessionVar('customer_id')) { $sql = "update %table.customers_basket%\n set customers_basket_quantity = '" . (double) $quantity . "'\n where customers_id = '" . (int) $this->getSessionVar('customer_id') . "'\n and products_id = '" . addslashes($products_id) . "'"; $this->getDb()->Execute($sql); } if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { //CLR 020606 check if input was from text box. If so, store additional attribute information //CLR 030108 check if text input is blank, if so do not update attribute lists //CLR 030228 add htmlspecialchars processing. This handles quotes and other special chars in the user input. $attr_value = NULL; $blank_value = FALSE; if (strstr($option, TEXT_PREFIX)) { if (trim($value) == NULL) { $blank_value = TRUE; } else { $option = substr($option, strlen(TEXT_PREFIX)); $attr_value = stripslashes($value); $value = PRODUCTS_OPTIONS_VALUES_TEXT_ID; $this->contents[$products_id]['attributes_values'][$option] = $attr_value; } } if (!$blank_value) { if (is_array($value)) { reset($value); while (list($opt, $val) = each($value)) { $this->contents[$products_id]['attributes'][$option . '_chk' . $val] = $val; } } else { $this->contents[$products_id]['attributes'][$option] = $value; } // update database //CLR 020606 update db insert to include attribute value_text. This is needed for text attributes. //CLR 030228 add addslashes() processing if ($attr_value) { $attr_value = addslashes($attr_value); } if (is_array($value)) { reset($value); while (list($opt, $val) = each($value)) { $products_options_sort_order = zen_get_attributes_options_sort_order(zen_get_prid($products_id), $option, $opt); $sql = "update %table.customers_basket_attributes%\n set products_options_value_id = '" . (int) $val . "'\n where customers_id = '" . (int) $this->getSessionVar('customer_id') . "'\n and products_id = '" . addslashes($products_id) . "'\n and products_options_id = '" . (int) $option . '_chk' . (int) $val . "'"; $this->getDb()->Execute($sql); } } else { if ($this->getSessionVar('customer_id')) { $sql = "update %table.customers_basket_attributes%\n set products_options_value_id = '" . (int) $value . "', products_options_value_text = '" . $attr_value . "'\n where customers_id = '" . (int) $this->getSessionVar('customer_id') . "'\n and products_id = '" . addslashes($products_id) . "'\n and products_options_id = '" . (int) $option . "'"; $this->getDb()->Execute($sql); } } } } } $this->cartID = $this->generate_cart_id(); $this->notify('NOTIFIER_CART_UPDATE_QUANTITY_END'); }
/** * Method to update a cart items quantity * * Changes the current quantity of a certain item in the cart to * a new value. Also updates the database stored cart if customer is * logged in. * * @param mixed product ID of item to update * @param decimal the quantity to update the item to * @param array product atributes attached to the item * @return void * @global object access to the db object */ function update_quantity($products_id, $quantity = '', $attributes = '') { global $db, $messageStack; if ($this->display_debug_messages) { $messageStack->add_session('header', 'FUNCTION ' . __FUNCTION__ . ' $products_id: ' . $products_id . ' $quantity: ' . $quantity, 'caution'); } if (!is_numeric($quantity) || $quantity < 0) { // adjust quantity when not a value $chk_link = '<a href="' . zen_href_link(zen_get_info_page($products_id), 'cPath=' . zen_get_generated_category_path_rev(zen_get_products_category_id($products_id)) . '&products_id=' . $products_id) . '">' . zen_get_products_name($products_id) . '</a>'; $messageStack->add_session('header', ERROR_CORRECTIONS_HEADING . ERROR_PRODUCT_QUANTITY_UNITS_SHOPPING_CART . $chk_link . ' ' . PRODUCTS_ORDER_QTY_TEXT . zen_output_string_protected($quantity), 'caution'); $quantity = 0; } $this->notify('NOTIFIER_CART_UPDATE_QUANTITY_START', array(), $products_id, $quantity, $attributes); if (empty($quantity)) { return true; } // nothing needs to be updated if theres no quantity, so we return true.. // bof: adjust new quantity to be same as current in stock $chk_current_qty = zen_get_products_stock($products_id); if (STOCK_ALLOW_CHECKOUT == 'false' && $quantity > $chk_current_qty) { $quantity = $chk_current_qty; if (!$this->flag_duplicate_msgs_set) { $messageStack->add_session('shopping_cart', ($this->display_debug_messages ? '$_GET[main_page]: ' . $_GET['main_page'] . ' FUNCTION ' . __FUNCTION__ . ': ' : '') . WARNING_PRODUCT_QUANTITY_ADJUSTED . zen_get_products_name($products_id), 'caution'); } } // eof: adjust new quantity to be same as current in stock $this->contents[$products_id] = array('qty' => (double) $quantity); // update database if (isset($_SESSION['customer_id'])) { $sql = "update " . TABLE_CUSTOMERS_BASKET . "\n set customers_basket_quantity = '" . (double) $quantity . "'\n where customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and products_id = '" . zen_db_input($products_id) . "'"; $db->Execute($sql); } if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { //CLR 020606 check if input was from text box. If so, store additional attribute information //CLR 030108 check if text input is blank, if so do not update attribute lists //CLR 030228 add htmlspecialchars processing. This handles quotes and other special chars in the user input. $attr_value = NULL; $blank_value = FALSE; if (strstr($option, TEXT_PREFIX)) { if (trim($value) == NULL) { $blank_value = TRUE; } else { $option = substr($option, strlen(TEXT_PREFIX)); $attr_value = stripslashes($value); $value = PRODUCTS_OPTIONS_VALUES_TEXT_ID; $this->contents[$products_id]['attributes_values'][$option] = $attr_value; } } if (!$blank_value) { if (is_array($value)) { reset($value); while (list($opt, $val) = each($value)) { $this->contents[$products_id]['attributes'][$option . '_chk' . $val] = $val; } } else { $this->contents[$products_id]['attributes'][$option] = $value; } // update database //CLR 020606 update db insert to include attribute value_text. This is needed for text attributes. //CLR 030228 add zen_db_input() processing // if (zen_session_is_registered('customer_id')) zen_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . zen_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . zen_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'"); if ($attr_value) { $attr_value = zen_db_input($attr_value); } if (is_array($value)) { reset($value); while (list($opt, $val) = each($value)) { $products_options_sort_order = zen_get_attributes_options_sort_order(zen_get_prid($products_id), $option, $opt); $sql = "update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . "\n set products_options_value_id = '" . (int) $val . "'\n where customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and products_id = '" . zen_db_input($products_id) . "'\n and products_options_id = '" . (int) $option . '_chk' . (int) $val . "'"; $db->Execute($sql); } } else { if (isset($_SESSION['customer_id'])) { $sql = "update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . "\n set products_options_value_id = '" . (int) $value . "', products_options_value_text = '" . $attr_value . "'\n where customers_id = '" . (int) $_SESSION['customer_id'] . "'\n and products_id = '" . zen_db_input($products_id) . "'\n and products_options_id = '" . (int) $option . "'"; $db->Execute($sql); } } } } } $this->cartID = $this->generate_cart_id(); $this->notify('NOTIFIER_CART_UPDATE_QUANTITY_END'); }
/** * Method to update a cart items quantity * * Changes the current quamtity of a certain item in the cart to * a new value. Also updates the database sored cart if customer is * logged in. * * @param mixed product ID of item to update * @param decimal the quantity to update the item to * @param array product atributes attached to the item * @return void * @global object access to the db object */ function update_quantity($products_id, $quantity = '', $attributes = '') { global $db; $this->notify('NOTIFIER_CART_UPDATE_QUANTITY_START'); if (empty($quantity)) { return true; } // nothing needs to be updated if theres no quantity, so we return true.. $this->contents[$products_id] = array('qty' => $quantity); // update database if (isset($_SESSION['customer_id'])) { $sql = "update " . TABLE_CUSTOMERS_BASKET . "\r\n set customers_basket_quantity = '" . (double) $quantity . "'\r\n where customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n and products_id = '" . zen_db_input($products_id) . "'"; $db->Execute($sql); } if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { //CLR 020606 check if input was from text box. If so, store additional attribute information //CLR 030108 check if text input is blank, if so do not update attribute lists //CLR 030228 add htmlspecialchars processing. This handles quotes and other special chars in the user input. $attr_value = NULL; $blank_value = FALSE; if (strstr($option, TEXT_PREFIX)) { if (trim($value) == NULL) { $blank_value = TRUE; } else { $option = substr($option, strlen(TEXT_PREFIX)); $attr_value = stripslashes($value); $value = PRODUCTS_OPTIONS_VALUES_TEXT_ID; $this->contents[$products_id]['attributes_values'][$option] = $attr_value; } } if (!$blank_value) { if (is_array($value)) { reset($value); while (list($opt, $val) = each($value)) { $this->contents[$products_id]['attributes'][$option . '_chk' . $val] = $val; } } else { $this->contents[$products_id]['attributes'][$option] = $value; } // update database //CLR 020606 update db insert to include attribute value_text. This is needed for text attributes. //CLR 030228 add zen_db_input() processing // if (zen_session_is_registered('customer_id')) zen_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . zen_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . zen_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'"); if ($attr_value) { $attr_value = zen_db_input($attr_value); } if (is_array($value)) { reset($value); while (list($opt, $val) = each($value)) { $products_options_sort_order = zen_get_attributes_options_sort_order(zen_get_prid($products_id), $option, $opt); $sql = "update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . "\r\n set products_options_value_id = '" . $val . "'\r\n where customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n and products_id = '" . zen_db_input($products_id) . "'\r\n and products_options_id = '" . (int) $option . '_chk' . $val . "'"; $db->Execute($sql); } } else { if (isset($_SESSION['customer_id'])) { $sql = "update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . "\r\n set products_options_value_id = '" . $value . "', products_options_value_text = '" . $attr_value . "'\r\n where customers_id = '" . (int) $_SESSION['customer_id'] . "'\r\n and products_id = '" . zen_db_input($products_id) . "'\r\n and products_options_id = '" . (int) $option . "'"; $db->Execute($sql); } } } } } $this->notify('NOTIFIER_CART_UPDATE_QUANTITY_END'); }