[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> shopping_cart.php (source)

   1  <?php
   2  /*

   3  $Id: shopping_cart.php 14 2006-07-28 17:42:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13    class shoppingCart {
  14      var $contents, $total, $weight, $cartID, $content_type;
  15  
  16  // LINE ADDED: MOD - indvship

  17  var $shiptotal;
  18  
  19      function shoppingCart() {
  20        $this->reset();
  21      }
  22  
  23      function restore_contents() {
  24  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

  25  //    global $customer_id;

  26        global $customer_id, $gv_id, $REMOTE_ADDR;
  27  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

  28  
  29        if (!tep_session_is_registered('customer_id')) return false;
  30  
  31  // insert current cart contents in database

  32        if (is_array($this->contents)) {
  33          reset($this->contents);
  34          while (list($products_id, ) = each($this->contents)) {
  35            $qty = $this->contents[$products_id]['qty'];
  36            $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
  37            if (!tep_db_num_rows($product_query)) {
  38              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) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
  39              if (isset($this->contents[$products_id]['attributes'])) {
  40                reset($this->contents[$products_id]['attributes']);
  41                while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
  42                  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) . "', '" . (int)$option . "', '" . (int)$value . "')");
  43                }
  44              }
  45            } else {
  46              tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
  47            }
  48          }
  49  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

  50          if (tep_session_is_registered('gv_id')) {
  51            $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $gv_id . "', '" . (int)$customer_id . "', now(),'" . $REMOTE_ADDR . "')");
  52            $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $gv_id . "'");
  53            tep_gv_account_update($customer_id, $gv_id);
  54            tep_session_unregister('gv_id');
  55          }
  56  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

  57        }
  58  
  59  // reset per-session cart contents, but not the database contents

  60        $this->reset(false);
  61  
  62        $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
  63        while ($products = tep_db_fetch_array($products_query)) {
  64          $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
  65  // attributes

  66          $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
  67          while ($attributes = tep_db_fetch_array($attributes_query)) {
  68            $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
  69          }
  70        }
  71  
  72        $this->cleanup();
  73      }
  74  
  75      function reset($reset_database = false) {
  76        global $customer_id;
  77  
  78        $this->contents = array();
  79        $this->total = 0;
  80        $this->weight = 0;
  81  //LINE ADDED: MOD - indvship

  82        $this->shiptotal = 0;
  83        $this->content_type = false;
  84  
  85        if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
  86          tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
  87          tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
  88        }
  89  
  90        unset($this->cartID);
  91        if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
  92      }
  93  
  94      function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
  95        global $new_products_id_in_cart, $customer_id;
  96  
  97        $products_id_string = tep_get_uprid($products_id, $attributes);
  98        $products_id = tep_get_prid($products_id_string);
  99  
 100        if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$qty > MAX_QTY_IN_CART)) {
 101          $qty = MAX_QTY_IN_CART;
 102        }
 103  
 104        $attributes_pass_check = true;
 105  
 106        if (is_array($attributes)) {
 107          reset($attributes);
 108          while (list($option, $value) = each($attributes)) {
 109            if (!is_numeric($option) || !is_numeric($value)) {
 110              $attributes_pass_check = false;
 111              break;
 112            }
 113          }
 114        }
 115  
 116        if (is_numeric($products_id) && is_numeric($qty) && ($attributes_pass_check == true)) {
 117          $check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
 118          $check_product = tep_db_fetch_array($check_product_query);
 119  
 120          if (($check_product !== false) && ($check_product['products_status'] == '1')) {
 121            if ($notify == true) {
 122              $new_products_id_in_cart = $products_id;
 123              tep_session_register('new_products_id_in_cart');
 124            }
 125  
 126            if ($this->in_cart($products_id_string)) {
 127              $this->update_quantity($products_id_string, $qty, $attributes);
 128            } else {
 129              $this->contents[$products_id_string] = array('qty' => (int)$qty);
 130  // insert into database

 131              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') . "')");
 132  
 133              if (is_array($attributes)) {
 134                reset($attributes);
 135                while (list($option, $value) = each($attributes)) {
 136                  $this->contents[$products_id_string]['attributes'][$option] = $value;
 137  // insert into database

 138                  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 . "')");
 139                }
 140              }
 141            }
 142  
 143            $this->cleanup();
 144  
 145  // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure

 146            $this->cartID = $this->generate_cart_id();
 147          }
 148        }
 149      }
 150  
 151      function update_quantity($products_id, $quantity = '', $attributes = '') {
 152        global $customer_id;
 153  
 154        $products_id_string = tep_get_uprid($products_id, $attributes);
 155        $products_id = tep_get_prid($products_id_string);
 156  
 157        if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$quantity > MAX_QTY_IN_CART)) {
 158          $quantity = MAX_QTY_IN_CART;
 159        }
 160  
 161        $attributes_pass_check = true;
 162  
 163        if (is_array($attributes)) {
 164          reset($attributes);
 165          while (list($option, $value) = each($attributes)) {
 166            if (!is_numeric($option) || !is_numeric($value)) {
 167              $attributes_pass_check = false;
 168              break;
 169            }
 170          }
 171        }
 172  
 173        if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity) && ($attributes_pass_check == true)) {
 174          $this->contents[$products_id_string] = array('qty' => (int)$quantity);
 175  // update database

 176          if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");
 177  
 178          if (is_array($attributes)) {
 179            reset($attributes);
 180            while (list($option, $value) = each($attributes)) {
 181              $this->contents[$products_id_string]['attributes'][$option] = $value;
 182  // update database

 183              if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "' and products_options_id = '" . (int)$option . "'");
 184            }
 185          }
 186        }
 187      }
 188  
 189      function cleanup() {
 190        global $customer_id;
 191  
 192        reset($this->contents);
 193        while (list($key,) = each($this->contents)) {
 194          if ($this->contents[$key]['qty'] < 1) {
 195            unset($this->contents[$key]);
 196  // remove from database

 197            if (tep_session_is_registered('customer_id')) {
 198              tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
 199              tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
 200            }
 201          }
 202        }
 203      }
 204  
 205      function count_contents() {  // get total number of items in cart 
 206        $total_items = 0;
 207        if (is_array($this->contents)) {
 208          reset($this->contents);
 209          while (list($products_id, ) = each($this->contents)) {
 210            $total_items += $this->get_quantity($products_id);
 211          }
 212        }
 213  
 214        return $total_items;
 215      }
 216  
 217      function get_quantity($products_id) {
 218        if (isset($this->contents[$products_id])) {
 219          return $this->contents[$products_id]['qty'];
 220        } else {
 221          return 0;
 222        }
 223      }
 224  
 225      function in_cart($products_id) {
 226        if (isset($this->contents[$products_id])) {
 227          return true;
 228        } else {
 229          return false;
 230        }
 231      }
 232  
 233      function remove($products_id) {
 234        global $customer_id;
 235  
 236        unset($this->contents[$products_id]);
 237  // remove from database

 238        if (tep_session_is_registered('customer_id')) {
 239          tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
 240          tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
 241        }
 242  
 243  // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure

 244        $this->cartID = $this->generate_cart_id();
 245      }
 246  
 247      function remove_all() {
 248        $this->reset();
 249      }
 250  
 251      function get_product_id_list() {
 252        $product_id_list = '';
 253        if (is_array($this->contents)) {
 254          reset($this->contents);
 255          while (list($products_id, ) = each($this->contents)) {
 256            $product_id_list .= ', ' . $products_id;
 257          }
 258        }
 259  
 260        return substr($product_id_list, 2);
 261      }
 262  
 263      function calculate() {
 264        global $currencies;
 265  
 266  //  LINE ADDED - MOD: CREDIT CLASS Gift Voucher Contribution

 267        $this->total_virtual = 0;
 268  
 269        $this->total = 0;
 270        $this->weight = 0;
 271  // LINE ADDED: MOD - indvship

 272        $this->shiptotal = 0;
 273        if (!is_array($this->contents)) return 0;
 274  
 275        reset($this->contents);
 276        while (list($products_id, ) = each($this->contents)) {
 277          $qty = $this->contents[$products_id]['qty'];
 278  
 279  // BOF: MOD - Separate Pricing Per Customer

 280  // global variable (session) $sppc_customer_group_id -> class variable cg_id

 281          global $sppc_customer_group_id;
 282          if(!tep_session_is_registered('sppc_customer_group_id')) { 
 283            $this->cg_id = '0';
 284          } else {
 285            $this->cg_id = $sppc_customer_group_id;
 286          }
 287  // EOF: MOD - Separate Pricing Per Customer  

 288  
 289  // LINE MOFIFIED - Added "products_ship_price"

 290          $product_query = tep_db_query("select products_id, products_price, products_ship_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
 291          if ($product = tep_db_fetch_array($product_query)) {
 292  
 293  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 294            $no_count = 1;
 295            $gv_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
 296            $gv_result = tep_db_fetch_array($gv_query);
 297            if (ereg('^GIFT', $gv_result['products_model'])) {
 298              $no_count = 0;
 299            }
 300  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 301  
 302            $prid = $product['products_id'];
 303            $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
 304            $products_price = $product['products_price'];
 305            $products_weight = $product['products_weight'];
 306            $products_length = $product['products_length'];
 307            $products_width = $product['products_width'];
 308            $products_height = $product['products_height'];
 309            $products_ready_to_ship = $product['products_ready_to_ship'];
 310  //LINE ADDED - mod indvship

 311            $products_ship_price = $product['products_ship_price'];
 312  
 313  // BOF: MOD - Separate Price per Customer Mod

 314  //          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

 315  //          if (tep_db_num_rows ($specials_query)) {

 316  //            $specials = tep_db_fetch_array($specials_query);

 317  //            $products_price = $specials['specials_new_products_price'];

 318  //          }

 319            $specials_price = tep_get_products_special_price((int)$prid);
 320            if (tep_not_null($specials_price)) {
 321              $products_price = $specials_price;
 322            } elseif ($this->cg_id != 0){
 323              $customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
 324              if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
 325                $products_price = $customer_group_price['customers_group_price'];
 326              }    
 327            }
 328  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 329            $this->total_virtual += tep_add_tax($products_price, $products_tax) * $qty * $no_count;// ICW CREDIT CLASS;

 330            $this->weight_virtual += ($qty * $products_weight) * $no_count;
 331  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 332  
 333            $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
 334  // LINE ADDED: MOD - indvship

 335            $this->shiptotal += ($products_ship_price * $qty);
 336            $this->weight += ($qty * $products_weight);
 337          }
 338  
 339  // attributes price

 340          if (isset($this->contents[$products_id]['attributes'])) {
 341            reset($this->contents[$products_id]['attributes']);
 342            while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
 343              $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
 344              $attribute_price = tep_db_fetch_array($attribute_price_query);
 345              if ($attribute_price['price_prefix'] == '+') {
 346                $this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
 347              } else {
 348                $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
 349              }
 350            }
 351          }
 352        }
 353      }
 354  
 355      function attributes_price($products_id) {
 356        $attributes_price = 0;
 357  
 358        if (isset($this->contents[$products_id]['attributes'])) {
 359          reset($this->contents[$products_id]['attributes']);
 360          while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
 361            $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
 362            $attribute_price = tep_db_fetch_array($attribute_price_query);
 363            if ($attribute_price['price_prefix'] == '+') {
 364              $attributes_price += $attribute_price['options_values_price'];
 365            } else {
 366              $attributes_price -= $attribute_price['options_values_price'];
 367            }
 368          }
 369        }
 370  
 371        return $attributes_price;
 372      }
 373  
 374      function get_products() {
 375        global $languages_id;
 376  // BOF Separate Pricing Per Customer

 377  // global variable (session) $sppc_customer_group_id -> class variable cg_id

 378        global $sppc_customer_group_id;
 379    
 380        if(!tep_session_is_registered('sppc_customer_group_id')) { 
 381        $this->cg_id = '0';
 382        } else {
 383          $this->cg_id = $sppc_customer_group_id;
 384        } 
 385  // EOF Separate Pricing Per Customer

 386        if (!is_array($this->contents)) return false;
 387  
 388        $products_array = array();
 389        reset($this->contents);
 390        while (list($products_id, ) = each($this->contents)) {
 391          $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
 392          if ($products = tep_db_fetch_array($products_query)) {
 393            $prid = $products['products_id'];
 394            $products_price = $products['products_price'];
 395  // BOF Separate Pricing Per Customer

 396  /*          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

 397            if (tep_db_num_rows($specials_query)) {

 398              $specials = tep_db_fetch_array($specials_query);

 399              $products_price = $specials['specials_new_products_price'];

 400            } */
 401            $specials_price = tep_get_products_special_price($prid);
 402            if (tep_not_null($specials_price)) {
 403              $products_price = $specials_price;
 404            } elseif ($this->cg_id != 0){
 405              $customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
 406            if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
 407              $products_price = $customer_group_price['customers_group_price'];
 408            }
 409          }
 410  // EOF Separate Pricing Per Customer

 411  //        $products_array[] = array('id' => $products_id,

 412            $products_array[] = array('id' => tep_get_uprid($products_id, $this->contents[$products_id]['attributes']),
 413                                      'name' => $products['products_name'],
 414                                      'model' => $products['products_model'],
 415                                      'image' => $products['products_image'],
 416                                      'price' => $products_price,
 417                                      'quantity' => $this->contents[$products_id]['qty'],
 418                                      'weight' => $products['products_weight'],
 419                                      'length' => $products['products_length'],
 420                                      'width' => $products['products_width'],
 421                                      'height' => $products['products_height'],
 422                                      'ready_to_ship' => $products['products_ready_to_ship'],
 423                                      'final_price' => ($products_price + $this->attributes_price($products_id)),
 424                                      'tax_class_id' => $products['products_tax_class_id'],
 425                                      'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
 426          }
 427        }
 428  
 429        return $products_array;
 430      }
 431  
 432      function show_total() {
 433        $this->calculate();
 434  
 435        return $this->total;
 436      }
 437  
 438  // BOF: MOD - Separate item shipping

 439  function get_shiptotal() {
 440      $this->calculate();
 441  
 442      return $this->shiptotal;
 443      }
 444  // EOF: MOD - Separate item shipping

 445  
 446      function show_weight() {
 447        $this->calculate();
 448  
 449        return $this->weight;
 450      }
 451  
 452  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 453      function show_total_virtual() {
 454        $this->calculate();
 455  
 456        return $this->total_virtual;
 457      }
 458  
 459      function show_weight_virtual() {
 460        $this->calculate();
 461  
 462        return $this->weight_virtual;
 463      }
 464  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 465  
 466      function generate_cart_id($length = 5) {
 467        return tep_create_random_value($length, 'digits');
 468      }
 469  
 470      function get_content_type() {
 471        $this->content_type = false;
 472  
 473        if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
 474          reset($this->contents);
 475          while (list($products_id, ) = each($this->contents)) {
 476            if (isset($this->contents[$products_id]['attributes'])) {
 477              reset($this->contents[$products_id]['attributes']);
 478              while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
 479                $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
 480                $virtual_check = tep_db_fetch_array($virtual_check_query);
 481  
 482                if ($virtual_check['total'] > 0) {
 483                  switch ($this->content_type) {
 484                    case 'physical':
 485                      $this->content_type = 'mixed';
 486  
 487                      return $this->content_type;
 488                      break;
 489                    default:
 490                      $this->content_type = 'virtual';
 491                      break;
 492                  }
 493                } else {
 494                  switch ($this->content_type) {
 495                    case 'virtual':
 496                      $this->content_type = 'mixed';
 497  
 498                      return $this->content_type;
 499                      break;
 500                    default:
 501                      $this->content_type = 'physical';
 502                      break;
 503                  }
 504                }
 505              }
 506  
 507  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 508            } elseif ($this->show_weight() == 0) {
 509              reset($this->contents);
 510              while (list($products_id, ) = each($this->contents)) {
 511                $virtual_check_query = tep_db_query("select products_weight from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");
 512                $virtual_check = tep_db_fetch_array($virtual_check_query);
 513                if ($virtual_check['products_weight'] == 0) {
 514                  switch ($this->content_type) {
 515                    case 'physical':
 516                      $this->content_type = 'mixed';
 517  
 518                      return $this->content_type;
 519                      break;
 520                    default:
 521                      $this->content_type = 'virtual';
 522                      break;
 523                  }
 524                } else {
 525                  switch ($this->content_type) {
 526                    case 'virtual':
 527                      $this->content_type = 'mixed';
 528  
 529                      return $this->content_type;
 530                      break;
 531                    default:
 532                      $this->content_type = 'physical';
 533                      break;
 534                  }
 535                }
 536              }
 537  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 538  
 539            } else {
 540              switch ($this->content_type) {
 541                case 'virtual':
 542                  $this->content_type = 'mixed';
 543  
 544                  return $this->content_type;
 545                  break;
 546                default:
 547                  $this->content_type = 'physical';
 548                  break;
 549              }
 550            }
 551          }
 552        } else {
 553          $this->content_type = 'physical';
 554        }
 555  
 556        return $this->content_type;
 557      }
 558  
 559      function unserialize($broken) {
 560        for(reset($broken);$kv=each($broken);) {
 561          $key=$kv['key'];
 562          if (gettype($this->$key)!="user function")
 563          $this->$key=$kv['value'];
 564        }
 565      }
 566  
 567  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 568  // amend count_contents to show nil contents for shipping

 569  // as we don't want to quote for 'virtual' item

 570  // GLOBAL CONSTANTS if NO_COUNT_ZERO_WEIGHT is true then we don't count any product with a weight

 571  // which is less than or equal to MINIMUM_WEIGHT

 572  // otherwise we just don't count gift certificates

 573      function count_contents_virtual() {  // get total number of items in cart disregard gift vouchers
 574        $total_items = 0;
 575        if (is_array($this->contents)) {
 576          reset($this->contents);
 577          while (list($products_id, ) = each($this->contents)) {
 578            $no_count = false;
 579            $gv_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");
 580            $gv_result = tep_db_fetch_array($gv_query);
 581            if (ereg('^GIFT', $gv_result['products_model'])) {
 582              $no_count=true;
 583            }
 584            if (NO_COUNT_ZERO_WEIGHT == 1) {
 585              $gv_query = tep_db_query("select products_weight from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($products_id) . "'");
 586              $gv_result=tep_db_fetch_array($gv_query);
 587              if ($gv_result['products_weight']<=MINIMUM_WEIGHT) {
 588                $no_count=true;
 589              }
 590            }
 591            if (!$no_count) $total_items += $this->get_quantity($products_id);
 592          }
 593        }
 594        return $total_items;
 595      }
 596  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 597    }
 598  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7