Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

748
 
809
 
809
 
shopping_cart.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shopping_cart.php 748 2006-08-23 11:26:56Z hpdl $
   3+  $Id: shopping_cart.php 809 2006-08-27 01:02:21Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
2222         $_products_in_stock = true;
  2323 
  2424     function osC_ShoppingCart() {
<> 25 -      if (isset($_SESSION['osC_ShoppingCart_data']) === false) {
   25+      if (!isset($_SESSION['osC_ShoppingCart_data'])) {
2626         $_SESSION['osC_ShoppingCart_data'] = array('contents' => array(),
  2727                                                    'sub_total_cost' => 0,
  2828                                                    'total_cost' => 0,
     
 !
6363     }
  6464 
  6565     function synchronizeWithDatabase() {
<> 66 -      global $osC_Database, $osC_Language, $osC_Customer, $osC_Image;
   66+      global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image;
6767 
<> 68 -      if ($osC_Customer->isLoggedOn() === false) {
   68+      if (!$osC_Customer->isLoggedOn()) {
6969         return false;
  7070       }
  7171 
  7272 // insert current cart contents in database
  7373       if ($this->hasContents()) {
<> 74 -        foreach ($this->_contents as $products_id => $data) {
   74+        foreach ($this->_contents as $products_id_string => $data) {
7575           $Qproduct = $osC_Database->query('select products_id, customers_basket_quantity from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  7676           $Qproduct->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  7777           $Qproduct->bindInt(':customers_id', $osC_Customer->getID());
<> 78 -          $Qproduct->bindValue(':products_id', $products_id);
   78+          $Qproduct->bindValue(':products_id', $products_id_string);
7979           $Qproduct->execute();
  8080 
  8181           if ($Qproduct->numberOfRows() > 0) {
  8282             $Qupdate = $osC_Database->query('update :table_customers_basket set customers_basket_quantity = :customers_basket_quantity where customers_id = :customers_id and products_id = :products_id');
  8383             $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  8484             $Qupdate->bindInt(':customers_basket_quantity', $data['quantity'] + $Qproduct->valueInt('customers_basket_quantity'));
  8585             $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
<> 86 -            $Qupdate->bindValue(':products_id', $products_id);
   86+            $Qupdate->bindValue(':products_id', $products_id_string);
8787             $Qupdate->execute();
  8888           } else {
  8989             $Qnew = $osC_Database->query('insert into :table_customers_basket (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values (:customers_id, :products_id, :customers_basket_quantity, now())');
  9090             $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  9191             $Qnew->bindInt(':customers_id', $osC_Customer->getID());
<> 92 -            $Qnew->bindValue(':products_id', $products_id);
   92+            $Qnew->bindValue(':products_id', $products_id_string);
9393             $Qnew->bindInt(':customers_basket_quantity', $data['quantity']);
  9494             $Qnew->execute();
<> 95 -
  96 -            if (isset($data['attributes'])) {
  97 -              foreach ($data['attributes'] as $option => $value) {
  98 -                $Qnew = $osC_Database->query('insert into :table_customers_basket_attributes (customers_id, products_id, products_options_id, products_options_value_id) values (:customers_id, :products_id, :products_options_id, :products_options_value_id)');
  99 -                $Qnew->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  100 -                $Qnew->bindInt(':customers_id', $osC_Customer->getID());
  101 -                $Qnew->bindValue(':products_id', $products_id);
  102 -                $Qnew->bindInt(':products_options_id', $option);
  103 -                $Qnew->bindInt(':products_options_value_id', $value['options_values_id']);
  104 -                $Qnew->execute();
  105 -              }
  106 -            }
10795           }
  10896         }
  10997       }
     
 !
122110       $Qproducts->execute();
  123111 
  124112       while ($Qproducts->next()) {
<>  113+        $product = explode('#', $Qproducts->value('products_id'), 2);
   114+        $attributes_array = array();
   115+
   116+        if (isset($product[1])) {
   117+          $attributes = explode(';', $product[1]);
   118+
   119+          foreach ($attributes as $set) {
   120+            $attribute = explode(':', $set);
   121+
   122+            if (!is_numeric($attribute[0]) || !is_numeric($attribute[1])) {
   123+              continue 2; // skip product
   124+            }
   125+
   126+            $attributes_array[$attribute[0]] = $attribute[1];
   127+          }
   128+        }
   129+
125130         $price = $Qproducts->value('products_price');
  126131 
<> 127 -        $Qspecials = $osC_Database->query('select specials_new_products_price from :table_specials where products_id = :products_id and status = 1');
  128 -        $Qspecials->bindTable(':table_specials', TABLE_SPECIALS);
  129 -        $Qspecials->bindInt(':products_id', osc_get_product_id($Qproducts->value('products_id')));
  130 -        $Qspecials->execute();
   132+        if ($osC_Services->isStarted('specials')) {
   133+          global $osC_Specials;
131134 
<> 132 -        if ($Qspecials->numberOfRows() > 0) {
  133 -          $price = $Qspecials->value('specials_new_products_price');
   135+          if ($new_price = $osC_Specials->getPrice(osc_get_product_id($Qproducts->value('products_id')))) {
   136+            $price = $new_price;
   137+          }
134138         }
  135139 
  136140         $this->_contents[$Qproducts->value('products_id')] = array('id' => $Qproducts->value('products_id'),
     
 !
145149                                                                    'date_added' => osC_DateTime::getShort($Qproducts->value('customers_basket_date_added')),
  146150                                                                    'weight_class_id' => $Qproducts->valueInt('products_weight_class'));
  147151 
<> 148 -        $Qattributes = $osC_Database->query('select cba.products_options_id, cba.products_options_value_id, po.products_options_name, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_customers_basket_attributes cba, :table_products_options po, :table_products_options_values pov, :table_products_attributes pa where cba.customers_id = 1 and cba.products_id = :products_id and pa.products_id = :products_id and cba.products_options_id = pa.options_id and pa.options_id = po.products_options_id and po.language_id = :language_id and cba.products_options_value_id = pa.options_values_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id');
  149 -        $Qattributes->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  150 -        $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
  151 -        $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
  152 -        $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
  153 -        $Qattributes->bindInt(':customers_id', $osC_Customer->getID());
  154 -        $Qattributes->bindValue(':products_id', $Qproducts->value('products_id'));
  155 -        $Qattributes->bindInt(':products_id', osc_get_product_id($Qproducts->value('products_id')));
  156 -        $Qattributes->bindInt(':language_id', $osC_Language->getID());
  157 -        $Qattributes->bindInt(':language_id', $osC_Language->getID());
  158 -        $Qattributes->execute();
   152+        if (!empty($attributes_array)) {
   153+          foreach ($attributes_array as $option_id => $value_id) {
   154+            $Qattributes = $osC_Database->query('select pa.options_values_price, pa.price_prefix, po.products_options_name, pov.products_options_values_name from :table_products_attributes pa, :table_products_options po, :table_products_options_values pov where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_values_id = :options_values_id and pa.options_id = po.products_options_id and po.language_id = :language_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id');
   155+            $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
   156+            $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
   157+            $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
   158+            $Qattributes->bindInt(':products_id', osc_get_product_id($Qproducts->value('products_id')));
   159+            $Qattributes->bindInt(':options_id', $option_id);
   160+            $Qattributes->bindInt(':options_values_id', $value_id);
   161+            $Qattributes->bindInt(':language_id', $osC_Language->getID());
   162+            $Qattributes->bindInt(':language_id', $osC_Language->getID());
   163+            $Qattributes->execute();
159164 
<> 160 -        while ($Qattributes->next()) {
  161 -          $this->_contents[$Qproducts->value('products_id')]['attributes'][$Qattributes->valueInt('products_options_id')] = array('options_id' => $Qattributes->valueInt('products_options_id'),
  162 -                                                                                                                                  'options_values_id' => $Qattributes->valueInt('products_options_value_id'),
  163 -                                                                                                                                  'products_options_name' => $Qattributes->value('products_options_name'),
  164 -                                                                                                                                  'products_options_values_name' => $Qattributes->value('products_options_values_name'),
  165 -                                                                                                                                  'options_values_price' => $Qattributes->value('options_values_price'),
  166 -                                                                                                                                  'price_prefix' => $Qattributes->value('price_prefix'));
   165+            while ($Qattributes->next()) {
   166+              $this->_contents[$Qproducts->value('products_id')]['attributes'][$option_id] = array('options_id' => $option_id,
   167+                                                                                                   'options_values_id' => $value_id,
   168+                                                                                                   'products_options_name' => $Qattributes->value('products_options_name'),
   169+                                                                                                   'products_options_values_name' => $Qattributes->value('products_options_values_name'),
   170+                                                                                                   'options_values_price' => $Qattributes->value('options_values_price'),
   171+                                                                                                   'price_prefix' => $Qattributes->value('price_prefix'));
167172 
<> 168 -          if ($Qattributes->value('price_prefix') == '+') {
  169 -            $this->_contents[$Qproducts->value('products_id')]['final_price'] += $Qattributes->value('options_values_price');
  170 -          } else {
  171 -            $this->_contents[$Qproducts->value('products_id')]['final_price'] -= $Qattributes->value('options_values_price');
   173+              if ($Qattributes->value('price_prefix') == '+') {
   174+                $this->_contents[$Qproducts->value('products_id')]['final_price'] += $Qattributes->value('options_values_price');
   175+              } else {
   176+                $this->_contents[$Qproducts->value('products_id')]['final_price'] -= $Qattributes->value('options_values_price');
   177+              }
   178+            }
172179           }
  173180         }
  174181       }
     
 !
181188       global $osC_Database, $osC_Customer;
  182189 
  183190       if (($reset_database === true) && $osC_Customer->isLoggedOn()) {
<> 184 -        $Qcheck = $osC_Database->query('select customers_basket_attributes_id from :table_customers_basket_attributes where customers_id = :customers_id limit 1');
  185 -        $Qcheck->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  186 -        $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
  187 -        $Qcheck->execute();
  188 -
  189 -        if ($Qcheck->numberOfRows() > 0) {
  190 -          $Qdelete = $osC_Database->query('delete from :table_customers_basket_attributes where customers_id = :customers_id');
  191 -          $Qdelete->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  192 -          $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
  193 -          $Qdelete->execute();
  194 -        }
  195 -
196191         $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id');
  197192         $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  198193         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
     
 !
214209       $this->resetBillingMethod();
  215210     }
  216211 
<> 217 -    function add($products_id, $attributes = '', $quantity = '') {
  218 -      global $osC_Database, $osC_Language, $osC_Customer, $osC_Image;
   212+    function add($products_id_string, $attributes = null, $quantity = null) {
   213+      global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image;
219214 
<> 220 -      $products_id_string = osc_get_product_id_string($products_id, $attributes);
   215+      $products_id_string = osc_get_product_id_string($products_id_string, $attributes);
221216       $products_id = osc_get_product_id($products_id_string);
  222217 
  223218       if (is_numeric($products_id)) {
     
 !
230225 
  231226         if ($Qcheck->valueInt('products_status') === 1) {
  232227           if ($this->exists($products_id_string)) {
<> 233 -            if (is_numeric($quantity) === false) {
   228+            if (!is_numeric($quantity)) {
234229               $quantity = $this->getQuantity($products_id_string) + 1;
  235230             }
  236231 
     
 !
246241               $Qupdate->execute();
  247242             }
  248243           } else {
<> 249 -            if (is_numeric($quantity) === false) {
   244+            if (!is_numeric($quantity)) {
250245               $quantity = 1;
  251246             }
  252247 
     
 !
258253 
  259254             $price = $Qcheck->value('products_price');
  260255 
<> 261 -            $Qspecials = $osC_Database->query('select specials_new_products_price from :table_specials where products_id = :products_id and status = 1');
  262 -            $Qspecials->bindTable(':table_specials', TABLE_SPECIALS);
  263 -            $Qspecials->bindInt(':products_id', $products_id);
  264 -            $Qspecials->execute();
   256+            if ($osC_Services->isStarted('specials')) {
   257+              global $osC_Specials;
265258 
<> 266 -            if ($Qspecials->numberOfRows() > 0) {
  267 -              $price = $Qspecials->value('specials_new_products_price');
   259+              if ($new_price = $osC_Specials->getPrice($products_id)) {
   260+                $price = $new_price;
   261+              }
268262             }
  269263 
  270264             $this->_contents[$products_id_string] = array('id' => $products_id_string,
     
 !
289283               $Qnew->execute();
  290284             }
  291285 
<> 292 -            if (is_array($attributes) && (empty($attributes) === false)) {
   286+            if (is_array($attributes) && !empty($attributes)) {
293287               foreach ($attributes as $option => $value) {
  294288                 $Qattributes = $osC_Database->query('select pa.options_values_price, pa.price_prefix, po.products_options_name, pov.products_options_values_name from :table_products_attributes pa, :table_products_options po, :table_products_options_values pov where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_values_id = :options_values_id and pa.options_id = po.products_options_id and po.language_id = :language_id and pa.options_values_id = pov.products_options_values_id and pov.language_id = :language_id');
  295289                 $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
     
 !
314308                 } else {
  315309                   $this->_contents[$products_id_string]['final_price'] -= $Qattributes->value('options_values_price');
  316310                 }
<> 317 -
  318 -// insert into database
  319 -                if ($osC_Customer->isLoggedOn()) {
  320 -                  $Qnew = $osC_Database->query('insert into :table_customers_basket_attributes (customers_id, products_id, products_options_id, products_options_value_id) values (:customers_id, :products_id, :products_options_id, :products_options_value_id)');
  321 -                  $Qnew->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  322 -                  $Qnew->bindInt(':customers_id', $osC_Customer->getID());
  323 -                  $Qnew->bindValue(':products_id', $products_id_string);
  324 -                  $Qnew->bindInt(':products_options_id', $option);
  325 -                  $Qnew->bindInt(':products_options_value_id', $value);
  326 -                  $Qnew->execute();
  327 -                }
328311               }
  329312             }
  330313           }
     
 !
366349 
  367350 // remove from database
  368351       if ($osC_Customer->isLoggedOn()) {
<> 369 -        $Qcheck = $osC_Database->query('select customers_basket_attributes_id from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id limit 1');
  370 -        $Qcheck->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  371 -        $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
  372 -        $Qcheck->bindValue(':products_id', $products_id);
  373 -        $Qcheck->execute();
  374 -
  375 -        if ($Qcheck->numberOfRows() > 0) {
  376 -          $Qdelete = $osC_Database->query('delete from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id');
  377 -          $Qdelete->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  378 -          $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
  379 -          $Qdelete->bindValue(':products_id', $products_id);
  380 -          $Qdelete->execute();
  381 -        }
  382 -
383352         $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  384353         $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  385354         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
     
 !
485454     }
  486455 
  487456     function hasAttributes($products_id) {
<> 488 -      return isset($this->_contents[$products_id]['attributes']) && (empty($this->_contents[$products_id]['attributes']) === false);
   457+      return isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes']);
489458     }
  490459 
  491460     function getAttributes($products_id) {
<> 492 -      if (isset($this->_contents[$products_id]['attributes']) && (empty($this->_contents[$products_id]['attributes']) === false)) {
   461+      if (isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes'])) {
493462         return $this->_contents[$products_id]['attributes'];
  494463       }
  495464     }
     
 !
544513                                        'suburb' => $Qaddress->valueProtected('entry_suburb'),
  545514                                        'city' => $Qaddress->valueProtected('entry_city'),
  546515                                        'postcode' => $Qaddress->valueProtected('entry_postcode'),
<> 547 -                                       'state' => (osc_empty($Qaddress->valueProtected('entry_state')) === false) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
   516+                                       'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
548517                                        'zone_id' => $Qaddress->valueInt('entry_zone_id'),
  549518                                        'zone_code' => $Qaddress->value('zone_code'),
  550519                                        'country_id' => $Qaddress->valueInt('entry_country_id'),
     
 !
632601                                       'suburb' => $Qaddress->valueProtected('entry_suburb'),
  633602                                       'city' => $Qaddress->valueProtected('entry_city'),
  634603                                       'postcode' => $Qaddress->valueProtected('entry_postcode'),
<> 635 -                                      'state' => (osc_empty($Qaddress->valueProtected('entry_state')) === false) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
   604+                                      'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
636605                                       'zone_id' => $Qaddress->valueInt('entry_zone_id'),
  637606                                       'zone_code' => $Qaddress->value('zone_code'),
  638607                                       'country_id' => $Qaddress->valueInt('entry_country_id'),
     
 !
734703 
  735704 // remove from database
  736705           if ($osC_Customer->isLoggedOn()) {
<> 737 -            $Qcheck = $osC_Database->query('select customers_basket_attributes_id from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id limit 1');
  738 -            $Qcheck->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  739 -            $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
  740 -            $Qcheck->bindValue(':products_id', $products_id);
  741 -            $Qcheck->execute();
  742 -
  743 -            if ($Qcheck->numberOfRows() > 0) {
  744 -              $Qdelete = $osC_Database->query('delete from :table_customers_basket_attributes where customers_id = :customers_id and products_id = :products_id');
  745 -              $Qdelete->bindTable(':table_customers_basket_attributes', TABLE_CUSTOMERS_BASKET_ATTRIBUTES);
  746 -              $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
  747 -              $Qdelete->bindValue(':products_id', $products_id);
  748 -              $Qdelete->execute();
  749 -            }
  750 -
751706             $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  752707             $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  753708             $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
     
 !
811766       }
  812767 
  813768       if ($set_shipping === true) {
<> 814 -        if (class_exists('osC_Shipping') === false) {
   769+        if (!class_exists('osC_Shipping')) {
815770           include('includes/classes/shipping.php');
  816771         }
  817772 
<> 818 -        if ( ($this->hasShippingMethod() === false) || ($this->getShippingMethod('is_cheapest') === true) ) {
   773+        if (!$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true)) {
819774           $osC_Shipping = new osC_Shipping();
  820775           $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false);
  821776         } else {
     
 !
824779         }
  825780       }
  826781 
<> 827 -      if (class_exists('osC_OrderTotal') === false) {
   782+      if (!class_exists('osC_OrderTotal')) {
<_ 828783         include('includes/classes/order_total.php');
  829784       }
  830785