[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/order_editor/ -> cart.php (source)

   1  <?php
   2  /*
   3    $Id: cart.php v5.0 07/19/2007 djmonkey1 Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2007 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    class manualCart {
  14      var $contents, $total, $weight;
  15  
  16      function manualCart() {
  17        $this->reset();
  18      }
  19  
  20      function restore_contents($orders_id) {
  21        $this->reset();
  22  
  23        $products_query = tep_db_query("select products_id, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders_id . "'");
  24        while ($products = tep_db_fetch_array($products_query)) {
  25          $this->contents[$products['products_id']] = array('qty' => $products['products_quantity']);
  26  /*
  27          $attributes_query = tep_db_query("select orders_products_attributes_id, products_options, products_options_values from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$orders_id . "' and orders_products_id = '" . $products['products_id'] . "'");
  28          while ($attributes = tep_db_fetch_array($attributes_query)) {
  29            $this->contents[$products['products_id']]['attributes'][$attributes['orders_products_attributes_id']] = $attributes['orders_products_attributes_id'];
  30          }
  31  */
  32        }
  33      }
  34  
  35      function reset() {
  36        $this->contents = array();
  37        $this->total = 0;
  38      }
  39  
  40      function count_contents() {  // get total number of items in cart 
  41          $total_items = 0;
  42          if (is_array($this->contents)) {
  43              reset($this->contents);
  44              while (list($products_id, ) = each($this->contents)) {
  45                  $total_items += $this->get_quantity($products_id);
  46              }
  47          }
  48          return $total_items;
  49      }
  50  
  51      function get_quantity($products_id) {
  52        if ($this->contents[$products_id]) {
  53          return $this->contents[$products_id]['qty'];
  54        } else {
  55          return 0;
  56        }
  57      }
  58  
  59      function in_cart($products_id) {
  60        if ($this->contents[$products_id]) {
  61          return true;
  62        } else {
  63          return false;
  64        }
  65      }
  66  
  67      function remove_all() {
  68        $this->reset();
  69      }
  70  
  71      function get_product_id_list() {
  72        $product_id_list = '';
  73        if (is_array($this->contents))
  74        {
  75          reset($this->contents);
  76          while (list($products_id, ) = each($this->contents)) {
  77            $product_id_list .= ', ' . $products_id;
  78          }
  79        }
  80        return substr($product_id_list, 2);
  81      }
  82  
  83      function calculate() {
  84        $this->total = 0;
  85        $this->weight = 0;
  86        if (!is_array($this->contents)) return 0;
  87  
  88        reset($this->contents);
  89        while (list($products_id, ) = each($this->contents)) {
  90          $qty = $this->contents[$products_id]['qty'];
  91  
  92  // products price
  93          $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . tep_get_prid($products_id) . "'");
  94          if ($product = tep_db_fetch_array($product_query)) {
  95            $prid = $product['products_id'];
  96            $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
  97            $products_price = $product['products_price'];
  98            $products_weight = $product['products_weight'];
  99  
 100            $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
 101            if (tep_db_num_rows ($specials_query)) {
 102              $specials = tep_db_fetch_array($specials_query);
 103              $products_price = $specials['specials_new_products_price'];
 104            }
 105  
 106            $this->total += tep_add_tax($products_price, $products_tax) * $qty;
 107            $this->weight += ($qty * $products_weight);
 108          }
 109  
 110  // attributes price
 111          if (isset($this->contents[$products_id]['attributes'])) {
 112            reset($this->contents[$products_id]['attributes']);
 113            while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
 114              $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
 115              $attribute_price = tep_db_fetch_array($attribute_price_query);
 116              if ($attribute_price['price_prefix'] == '+') {
 117                $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
 118              } else {
 119                $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
 120              }
 121            }
 122          }
 123        }
 124      }
 125  
 126      function attributes_price($products_id) {
 127        if ($this->contents[$products_id]['attributes']) {
 128          reset($this->contents[$products_id]['attributes']);
 129          while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
 130            $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $products_id . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
 131            $attribute_price = tep_db_fetch_array($attribute_price_query);
 132            if ($attribute_price['price_prefix'] == '+') {
 133              $attributes_price += $attribute_price['options_values_price'];
 134            } else {
 135              $attributes_price -= $attribute_price['options_values_price'];
 136            }
 137          }
 138        }
 139  
 140        return $attributes_price;
 141      }
 142  
 143      function get_products() {
 144        global $languages_id;
 145  
 146        if (!is_array($this->contents)) return 0;
 147        $products_array = array();
 148        reset($this->contents);
 149        while (list($products_id, ) = each($this->contents)) {
 150          $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id='" . tep_get_prid($products_id) . "' and pd.products_id = p.products_id and pd.language_id = '" . $languages_id . "'");
 151          if ($products = tep_db_fetch_array($products_query)) {
 152            $prid = $products['products_id'];
 153            $products_price = $products['products_price'];
 154  
 155            $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
 156            if (tep_db_num_rows($specials_query)) {
 157              $specials = tep_db_fetch_array($specials_query);
 158              $products_price = $specials['specials_new_products_price'];
 159            }
 160  
 161            $products_array[] = array('id' => $products_id,
 162                                      'name' => $products['products_name'],
 163                                      'model' => $products['products_model'],
 164                                      'price' => $products_price,
 165                                      'quantity' => $this->contents[$products_id]['qty'],
 166                                      'weight' => $products['products_weight'],
 167                                      'final_price' => ($products_price + $this->attributes_price($products_id)),
 168                                      'tax_class_id' => $products['products_tax_class_id'],
 169                                      'attributes' => $this->contents[$products_id]['attributes']);
 170          }
 171        }
 172        return $products_array;
 173      }
 174  
 175      function show_total() {
 176        $this->calculate();
 177  
 178        return $this->total;
 179      }
 180  
 181      function show_weight() {
 182        $this->calculate();
 183  
 184        return $this->weight;
 185      }
 186  
 187      function dist_allowed() {      
 188        $allowed = true;     
 189        if (is_array($this->contents)) {        
 190          reset($this->contents);        
 191          while (list($products_id, ) = each($this->contents)) {                                                       
 192            $distributor_query = tep_db_query("select distributors_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
 193            $distributor = tep_db_fetch_array($distributor_query);
 194          
 195            if ($distributor['distributors_id'] == '1') {        
 196              $allowed = false;        
 197              break;      
 198            }       
 199          }     
 200        }      
 201      
 202        return $allowed;    
 203      }
 204   
 205      function unserialize($broken) {
 206        for(reset($broken);$kv=each($broken);) {
 207          $key=$kv['key'];
 208          if (gettype($this->$key)!="user function")
 209          $this->$key=$kv['value'];
 210        }
 211      }
 212  
 213    }
 214  ?>


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