Ejemplo n.º 1
0
 function add_cart($products_id, $qty = '1', $attributes = '', $notify = true)
 {
     global $new_products_id_in_cart, $customer_id;
     $products_id_string = tep_get_uprid($products_id, $attributes);
     $products_id = tep_get_prid($products_id_string);
     if (defined('MAX_QTY_IN_CART') && MAX_QTY_IN_CART > 0 && (int) $qty > MAX_QTY_IN_CART) {
         $qty = MAX_QTY_IN_CART;
     }
     // BOF QPBPP for SPPC
     $pf = new PriceFormatter();
     $pf->loadProduct($products_id);
     $qty = $pf->adjustQty($qty);
     $discount_category = $pf->get_discount_category();
     // EOF QPBPP for SPPC
     $attributes_pass_check = true;
     if (is_array($attributes)) {
         reset($attributes);
         while (list($option, $value) = each($attributes)) {
             if (!is_numeric($option) || !is_numeric($value)) {
                 $attributes_pass_check = false;
                 break;
             }
         }
     }
     if (is_numeric($products_id) && is_numeric($qty) && $attributes_pass_check == true) {
         $check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int) $products_id . "'");
         $check_product = tep_db_fetch_array($check_product_query);
         if ($check_product !== false && $check_product['products_status'] == '1') {
             if ($notify == true) {
                 $new_products_id_in_cart = $products_id;
                 tep_session_register('new_products_id_in_cart');
             }
             // BOF QPBPP for SPPC
             if ($this->in_cart($products_id_string)) {
                 $this->update_quantity($products_id_string, $qty, $attributes, $discount_category);
             } else {
                 $this->contents[$products_id_string] = array('qty' => (int) $qty, 'discount_categories_id' => $discount_category);
                 // EOF QPBPP for SPPC
                 // insert into database
                 if (tep_session_is_registered('customer_id')) {
                     tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int) $qty . "', '" . date('Ymd') . "')");
                 }
                 if (is_array($attributes)) {
                     reset($attributes);
                     while (list($option, $value) = each($attributes)) {
                         $this->contents[$products_id_string]['attributes'][$option] = $value;
                         // insert into database
                         if (tep_session_is_registered('customer_id')) {
                             tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int) $option . "', '" . (int) $value . "')");
                         }
                     }
                 }
             }
             $this->cleanup();
             // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
             $this->cartID = $this->generate_cart_id();
         }
     }
 }