Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1497
 
1674
 
1674
 
shopping_cart.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shopping_cart.php 1497 2007-03-29 13:40:05Z hpdl $
   3+  $Id: shopping_cart.php 1674 2007-08-20 22:56:00Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1313 */
  1414 
  1515   class osC_ShoppingCart {
<> 16 -    var $_contents = array(),
  17 -        $_sub_total = 0,
  18 -        $_total = 0,
  19 -        $_weight = 0,
  20 -        $_tax = 0,
  21 -        $_tax_groups = array(),
  22 -        $_content_type,
  23 -        $_products_in_stock = true;
   16+    private $_contents = array();
   17+    private $_sub_total = 0;
   18+    private $_total = 0;
   19+    private $_weight = 0;
   20+    private $_tax = 0;
   21+    private $_tax_groups = array();
   22+    private $_content_type;
   23+    private $_products_in_stock = true;
2424 
<> 25 -    function osC_ShoppingCart() {
  26 -      if (!isset($_SESSION['osC_ShoppingCart_data'])) {
   25+    public function __construct() {
   26+      if ( !isset($_SESSION['osC_ShoppingCart_data']) ) {
2727         $_SESSION['osC_ShoppingCart_data'] = array('contents' => array(),
  2828                                                    'sub_total_cost' => 0,
  2929                                                    'total_cost' => 0,
     
 !
5959       $this->_order_totals =& $_SESSION['osC_ShoppingCart_data']['order_totals'];
  6060     }
  6161 
<> 62 -    function update() {
   62+    public function update() {
6363       if ( !isset($_SESSION['cartID']) ) {
  6464         $this->_calculate();
  6565       }
  6666     }
  6767 
<> 68 -    function hasContents() {
   68+    public function hasContents() {
6969       return !empty($this->_contents);
  7070     }
  7171 
<> 72 -    function synchronizeWithDatabase() {
  73 -      global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image;
   72+    public function synchronizeWithDatabase() {
   73+      global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Specials;
7474 
<> 75 -      if (!$osC_Customer->isLoggedOn()) {
   75+      if ( !$osC_Customer->isLoggedOn() ) {
7676         return false;
  7777       }
  7878 
  7979 // insert current cart contents in database
<> 80 -      if ($this->hasContents()) {
  81 -        foreach ($this->_contents as $products_id_string => $data) {
   80+      if ( $this->hasContents() ) {
   81+        foreach ( $this->_contents as $product_id => $data ) {
8282           $Qproduct = $osC_Database->query('select products_id, customers_basket_quantity from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  8383           $Qproduct->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  8484           $Qproduct->bindInt(':customers_id', $osC_Customer->getID());
<> 85 -          $Qproduct->bindValue(':products_id', $products_id_string);
   85+          $Qproduct->bindInt(':products_id', $product_id);
8686           $Qproduct->execute();
  8787 
<> 88 -          if ($Qproduct->numberOfRows() > 0) {
   88+          if ( $Qproduct->numberOfRows() > 0 ) {
8989             $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');
  9090             $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  9191             $Qupdate->bindInt(':customers_basket_quantity', $data['quantity'] + $Qproduct->valueInt('customers_basket_quantity'));
  9292             $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
<> 93 -            $Qupdate->bindValue(':products_id', $products_id_string);
   93+            $Qupdate->bindInt(':products_id', $product_id);
9494             $Qupdate->execute();
  9595           } else {
  9696             $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())');
  9797             $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  9898             $Qnew->bindInt(':customers_id', $osC_Customer->getID());
<> 99 -            $Qnew->bindValue(':products_id', $products_id_string);
   99+            $Qnew->bindValue(':products_id', $product_id);
100100             $Qnew->bindInt(':customers_basket_quantity', $data['quantity']);
  101101             $Qnew->execute();
  102102           }
     
 !
106106 // reset per-session cart contents, but not the database contents
  107107       $this->reset();
  108108 
<> 109 -      $Qproducts = $osC_Database->query('select cb.products_id, cb.customers_basket_quantity, cb.customers_basket_date_added, p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, pd.products_name, pd.products_keyword, i.image from :table_customers_basket cb, :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag), :table_products_description pd where cb.customers_id = :customers_id and cb.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = :language_id order by cb.customers_basket_date_added desc');
   109+      $_delete_array = array();
   110+
   111+      $Qproducts = $osC_Database->query('select cb.products_id, cb.customers_basket_quantity, cb.customers_basket_date_added, p.parent_id, p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, p.products_status from :table_customers_basket cb, :table_products p where cb.customers_id = :customers_id and cb.products_id = p.products_id order by cb.customers_basket_date_added desc');
110112       $Qproducts->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  111113       $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
<> 112 -      $Qproducts->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
  113 -      $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
  114 -      $Qproducts->bindInt(':default_flag', 1);
115114       $Qproducts->bindInt(':customers_id', $osC_Customer->getID());
<> 116 -      $Qproducts->bindInt(':language_id', $osC_Language->getID());
117115       $Qproducts->execute();
  118116 
<> 119 -      while ($Qproducts->next()) {
  120 -        $product = explode('#', $Qproducts->value('products_id'), 2);
  121 -        $attributes_array = array();
   117+      while ( $Qproducts->next() ) {
   118+        if ( $Qproducts->valueInt('products_status') === 1 ) {
   119+          $Qdesc = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
   120+          $Qdesc->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
   121+          $Qdesc->bindInt(':products_id', ($Qproducts->valueInt('parent_id') > 0) ? $Qproducts->valueInt('parent_id') : $Qproducts->valueInt('products_id'));
   122+          $Qdesc->bindInt(':language_id', $osC_Language->getID());
   123+          $Qdesc->execute();
122124 
<> 123 -        if (isset($product[1])) {
  124 -          $attributes = explode(';', $product[1]);
   125+          $Qimage = $osC_Database->query('select image from :table_products_images where products_id = :products_id and i.default_flag = :default_flag');
   126+          $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
   127+          $Qimage->bindInt(':products_id', ($Qproducts->valueInt('parent_id') > 0) ? $Qproducts->valueInt('parent_id') : $Qproducts->valueInt('products_id'));
   128+          $Qimage->bindInt(':default_flag', 1);
   129+          $Qimage->execute();
125130 
<> 126 -          foreach ($attributes as $set) {
  127 -            $attribute = explode(':', $set);
   131+          $price = $Qproducts->value('products_price');
128132 
<> 129 -            if (!is_numeric($attribute[0]) || !is_numeric($attribute[1])) {
  130 -              continue 2; // skip product
   133+          if ( $osC_Services->isStarted('specials') ) {
   134+            if ( $new_price = $osC_Specials->getPrice($Qproducts->valueInt('products_id')) ) {
   135+              $price = $new_price;
131136             }
<> 132 -
  133 -            $attributes_array[$attribute[0]] = $attribute[1];
134137           }
<> 135 -        }
136138 
<> 137 -        $price = $Qproducts->value('products_price');
   139+          $this->_contents[$Qproducts->valueInt('products_id')] = array('id' => $Qproducts->valueInt('products_id'),
   140+                                                                        'parent_id' => $Qproducts->valueInt('parent_id'),
   141+                                                                        'name' => $Qdesc->value('products_name'),
   142+                                                                        'keyword' => $Qdesc->value('products_keyword'),
   143+                                                                        'image' => ($Qimage->numberOfRows() === 1) ? $Qimage->value('image') : '',
   144+                                                                        'price' => $price,
   145+                                                                        'quantity' => $Qproducts->valueInt('customers_basket_quantity'),
   146+                                                                        'weight' => $Qproducts->value('products_weight'),
   147+                                                                        'tax_class_id' => $Qproducts->valueInt('products_tax_class_id'),
   148+                                                                        'date_added' => osC_DateTime::getShort($Qproducts->value('customers_basket_date_added')),
   149+                                                                        'weight_class_id' => $Qproducts->valueInt('products_weight_class'));
138150 
<> 139 -        if ($osC_Services->isStarted('specials')) {
  140 -          global $osC_Specials;
   151+          if ( $Qproducts->valueInt('parent_id') > 0 ) {
   152+            $Qcheck = $osC_Database->query('select products_status from :table_products where products_id = :products_id');
   153+            $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
   154+            $Qcheck->bindInt(':products_id', $Qproducts->valueInt('parent_id'));
   155+            $Qcheck->execute();
141156 
<> 142 -          if ($new_price = $osC_Specials->getPrice(osc_get_product_id($Qproducts->value('products_id')))) {
  143 -            $price = $new_price;
  144 -          }
  145 -        }
   157+            if ( $Qcheck->valueInt('products_status') === 1 ) {
   158+              $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg where pv.products_id = :products_id and pv.variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id');
   159+              $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
   160+              $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
   161+              $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
   162+              $Qvariant->bindInt(':products_id', $Qproducts->valueInt('products_id'));
   163+              $Qvariant->bindInt(':languages_id', $osC_Language->getID());
   164+              $Qvariant->bindInt(':languages_id', $osC_Language->getID());
   165+              $Qvariant->execute();
146166 
<> 147 -        $this->_contents[$Qproducts->value('products_id')] = array('id' => $Qproducts->value('products_id'),
  148 -                                                                   'name' => $Qproducts->value('products_name'),
  149 -                                                                   'keyword' => $Qproducts->value('products_keyword'),
  150 -                                                                   'image' => $Qproducts->value('image'),
  151 -                                                                   'price' => $price,
  152 -                                                                   'final_price' => $price,
  153 -                                                                   'quantity' => $Qproducts->valueInt('customers_basket_quantity'),
  154 -                                                                   'weight' => $Qproducts->value('products_weight'),
  155 -                                                                   'tax_class_id' => $Qproducts->valueInt('products_tax_class_id'),
  156 -                                                                   'date_added' => osC_DateTime::getShort($Qproducts->value('customers_basket_date_added')),
  157 -                                                                   'weight_class_id' => $Qproducts->valueInt('products_weight_class'));
  158 -
  159 -        if (!empty($attributes_array)) {
  160 -          foreach ($attributes_array as $option_id => $value_id) {
  161 -            $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');
  162 -            $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
  163 -            $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
  164 -            $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
  165 -            $Qattributes->bindInt(':products_id', osc_get_product_id($Qproducts->value('products_id')));
  166 -            $Qattributes->bindInt(':options_id', $option_id);
  167 -            $Qattributes->bindInt(':options_values_id', $value_id);
  168 -            $Qattributes->bindInt(':language_id', $osC_Language->getID());
  169 -            $Qattributes->bindInt(':language_id', $osC_Language->getID());
  170 -            $Qattributes->execute();
  171 -
  172 -            if ($Qattributes->numberOfRows() > 0) {
  173 -              $this->_contents[$Qproducts->value('products_id')]['attributes'][$option_id] = array('options_id' => $option_id,
  174 -                                                                                                   'options_values_id' => $value_id,
  175 -                                                                                                   'products_options_name' => $Qattributes->value('products_options_name'),
  176 -                                                                                                   'products_options_values_name' => $Qattributes->value('products_options_values_name'),
  177 -                                                                                                   'options_values_price' => $Qattributes->value('options_values_price'),
  178 -                                                                                                   'price_prefix' => $Qattributes->value('price_prefix'));
  179 -
  180 -              if ($Qattributes->value('price_prefix') == '+') {
  181 -                $this->_contents[$Qproducts->value('products_id')]['final_price'] += $Qattributes->value('options_values_price');
   167+              if ( $Qproducts->numberOfRows() > 0 ) {
   168+                while ( $Qvariant->next() ) {
   169+                  $this->_contents[$Qproducts->valueInt('products_id')]['variants'][$Qvariant->valueInt('group_id')] = array('group_id' => $Qvariant->valueInt('group_id'),
   170+                                                                                                                             'value_id' => $Qvariant->valueInt('value_id'),
   171+                                                                                                                             'group_title' => $Qvariant->value('group_title'),
   172+                                                                                                                             'value_title' => $Qvariant->value('value_title'));
   173+                }
182174               } else {
<> 183 -                $this->_contents[$Qproducts->value('products_id')]['final_price'] -= $Qattributes->value('options_values_price');
   175+                $_delete_array[] = $Qproducts->valueInt('products_id');
184176               }
  185177             } else {
<> 186 -              unset($this->_contents[$Qproducts->value('products_id')]);
  187 -              continue 2; // skip product
   178+              $_delete_array[] = $Qproducts->valueInt('products_id');
188179             }
  189180           }
<>  181+        } else {
   182+          $_delete_array[] = $Qproducts->valueInt('products_id');
190183         }
  191184       }
  192185 
<>  186+      if ( !empty($_delete_array) ) {
   187+        foreach ( $_delete_array as $product_id ) {
   188+          unset($this->_contents[$product_id]);
   189+        }
   190+
   191+        $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id in (":products_id")');
   192+        $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   193+        $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
   194+        $Qdelete->bindRaw(':products_id', implode('", "', $_delete_array));
   195+        $Qdelete->execute();
   196+      }
   197+
193198       $this->_cleanUp();
  194199       $this->_calculate();
  195200     }
  196201 
<> 197 -    function reset($reset_database = false) {
   202+    public function reset($reset_database = false) {
198203       global $osC_Database, $osC_Customer;
  199204 
<> 200 -      if (($reset_database === true) && $osC_Customer->isLoggedOn()) {
   205+      if ( ($reset_database === true) && $osC_Customer->isLoggedOn() ) {
201206         $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id');
  202207         $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  203208         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
     
 !
222227       }
  223228     }
  224229 
<> 225 -    function add($products_id_string, $attributes = null, $quantity = null) {
  226 -      global $osC_Database, $osC_Services, $osC_Language, $osC_Customer, $osC_Image;
   230+    public function add($product_id, $quantity = null) {
   231+      global $osC_Database, $osC_Services, $osC_Language, $osC_Customer;
227232 
<> 228 -      $products_id_string = osc_get_product_id_string($products_id_string, $attributes);
  229 -      $products_id = osc_get_product_id($products_id_string);
   233+      if ( is_numeric($product_id) ) {
   234+        $Qproduct = $osC_Database->query('select p.parent_id, p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, p.products_status, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id');
   235+        $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
   236+        $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
   237+        $Qproduct->bindInt(':default_flag', 1);
   238+        $Qproduct->bindInt(':products_id', $product_id);
   239+        $Qproduct->execute();
230240 
<> 231 -      if (is_numeric($products_id)) {
  232 -        $Qcheck = $osC_Database->query('select p.products_price, p.products_tax_class_id, p.products_weight, p.products_weight_class, p.products_status, i.image from :table_products p left join :table_products_images i on (p.products_id = i.products_id and i.default_flag = :default_flag) where p.products_id = :products_id');
  233 -        $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
  234 -        $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
  235 -        $Qcheck->bindInt(':default_flag', 1);
  236 -        $Qcheck->bindInt(':products_id', $products_id);
  237 -        $Qcheck->execute();
  238 -
  239 -        if ($Qcheck->valueInt('products_status') === 1) {
  240 -          if ($this->exists($products_id_string)) {
  241 -            if (!is_numeric($quantity)) {
  242 -              $quantity = $this->getQuantity($products_id_string) + 1;
   241+        if ( $Qproduct->valueInt('products_status') === 1 ) {
   242+          if ( $this->exists($product_id) ) {
   243+            if ( !is_numeric($quantity) ) {
   244+              $quantity = $this->getQuantity($product_id) + 1;
243245             }
  244246 
<> 245 -            $this->_contents[$products_id_string]['quantity'] = $quantity;
   247+            $this->_contents[$product_id]['quantity'] = $quantity;
246248 
<> 247 -// update database
  248 -            if ($osC_Customer->isLoggedOn()) {
   249+            if ( $osC_Customer->isLoggedOn() ) {
249250               $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');
  250251               $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  251252               $Qupdate->bindInt(':customers_basket_quantity', $quantity);
  252253               $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
<> 253 -              $Qupdate->bindValue(':products_id', $products_id_string);
   254+              $Qupdate->bindInt(':products_id', $product_id);
254255               $Qupdate->execute();
  255256             }
  256257           } else {
<> 257 -            if (!is_numeric($quantity)) {
   258+            if ( !is_numeric($quantity) ) {
258259               $quantity = 1;
  259260             }
  260261 
<> 261 -            $Qproduct = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
  262 -            $Qproduct->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
  263 -            $Qproduct->bindInt(':products_id', $products_id);
  264 -            $Qproduct->bindInt(':language_id', $osC_Language->getID());
  265 -            $Qproduct->execute();
   262+            $Qdescription = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
   263+            $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
   264+            $Qdescription->bindInt(':products_id', ($Qproduct->valueInt('parent_id') > 0) ? $Qproduct->valueInt('parent_id') : $product_id);
   265+            $Qdescription->bindInt(':language_id', $osC_Language->getID());
   266+            $Qdescription->execute();
266267 
<> 267 -            $price = $Qcheck->value('products_price');
   268+            $price = $Qproduct->value('products_price');
268269 
<> 269 -            if ($osC_Services->isStarted('specials')) {
   270+            if ( $osC_Services->isStarted('specials') ) {
270271               global $osC_Specials;
  271272 
<> 272 -              if ($new_price = $osC_Specials->getPrice($products_id)) {
   273+              if ( $new_price = $osC_Specials->getPrice($product_id) ) {
273274                 $price = $new_price;
  274275               }
  275276             }
  276277 
<> 277 -            $this->_contents[$products_id_string] = array('id' => $products_id_string,
  278 -                                                          'name' => $Qproduct->value('products_name'),
  279 -                                                          'keyword' => $Qproduct->value('products_keyword'),
  280 -                                                          'image' => $Qcheck->value('image'),
  281 -                                                          'price' => $price,
  282 -                                                          'final_price' => $price,
  283 -                                                          'quantity' => $quantity,
  284 -                                                          'weight' => $Qcheck->value('products_weight'),
  285 -                                                          'tax_class_id' => $Qcheck->valueInt('products_tax_class_id'),
  286 -                                                          'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()),
  287 -                                                          'weight_class_id' => $Qcheck->valueInt('products_weight_class'));
   278+            $this->_contents[$product_id] = array('id' => $product_id,
   279+                                                  'parent_id' => $Qproduct->valueInt('parent_id'),
   280+                                                  'name' => $Qdescription->value('products_name'),
   281+                                                  'keyword' => $Qdescription->value('products_keyword'),
   282+                                                  'image' => $Qproduct->value('image'),
   283+                                                  'price' => $price,
   284+                                                  'quantity' => $quantity,
   285+                                                  'weight' => $Qproduct->value('products_weight'),
   286+                                                  'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'),
   287+                                                  'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()),
   288+                                                  'weight_class_id' => $Qproduct->valueInt('products_weight_class'));
288289 
<> 289 -// insert into database
  290 -            if ($osC_Customer->isLoggedOn()) {
   290+            if ( $osC_Customer->isLoggedOn() ) {
291291               $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())');
  292292               $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  293293               $Qnew->bindInt(':customers_id', $osC_Customer->getID());
<> 294 -              $Qnew->bindValue(':products_id', $products_id_string);
   294+              $Qnew->bindInt(':products_id', $product_id);
295295               $Qnew->bindInt(':customers_basket_quantity', $quantity);
  296296               $Qnew->execute();
  297297             }
  298298 
<> 299 -            if (is_array($attributes) && !empty($attributes)) {
  300 -              foreach ($attributes as $option => $value) {
  301 -                $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');
  302 -                $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
  303 -                $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
  304 -                $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
  305 -                $Qattributes->bindValue(':products_id', $products_id);
  306 -                $Qattributes->bindInt(':options_id', $option);
  307 -                $Qattributes->bindInt(':options_values_id', $value);
  308 -                $Qattributes->bindInt(':language_id', $osC_Language->getID());
  309 -                $Qattributes->bindInt(':language_id', $osC_Language->getID());
  310 -                $Qattributes->execute();
   299+            if ( $Qproduct->valueInt('parent_id') > 0 ) {
   300+              $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvv.id as value_id, pvv.title as value_title from :table_products_variants pv, :table_products_variants_values pvv, :table_products_variants_groups pvg where pv.products_id = :products_id and pv.variants_values_id = pvv.id and pvv.languages_id = :languages_id and pvv.products_variants_groups_id = pvg.id and pvg.languages_id = :languages_id');
   301+              $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
   302+              $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
   303+              $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
   304+              $Qvariant->bindInt(':products_id', $product_id);
   305+              $Qvariant->bindInt(':languages_id', $osC_Language->getID());
   306+              $Qvariant->bindInt(':languages_id', $osC_Language->getID());
   307+              $Qvariant->execute();
311308 
<> 312 -                $this->_contents[$products_id_string]['attributes'][$option] = array('options_id' => $option,
  313 -                                                                                     'options_values_id' => $value,
  314 -                                                                                     'products_options_name' => $Qattributes->value('products_options_name'),
  315 -                                                                                     'products_options_values_name' => $Qattributes->value('products_options_values_name'),
  316 -                                                                                     'options_values_price' => $Qattributes->value('options_values_price'),
  317 -                                                                                     'price_prefix' => $Qattributes->value('price_prefix'));
  318 -
  319 -                if ($Qattributes->value('price_prefix') == '+') {
  320 -                  $this->_contents[$products_id_string]['final_price'] += $Qattributes->value('options_values_price');
  321 -                } else {
  322 -                  $this->_contents[$products_id_string]['final_price'] -= $Qattributes->value('options_values_price');
  323 -                }
   309+              while ( $Qvariant->next() ) {
   310+                $this->_contents[$product_id]['variants'][$Qvariant->valueInt('group_id')] = array('group_id' => $Qvariant->valueInt('group_id'),
   311+                                                                                                   'value_id' => $Qvariant->valueInt('value_id'),
   312+                                                                                                   'group_title' => $Qvariant->value('group_title'),
   313+                                                                                                   'value_title' => $Qvariant->value('value_title'));
324314               }
  325315             }
  326316           }
     
 !
331321       }
  332322     }
  333323 
<> 334 -    function numberOfItems() {
   324+    public function numberOfItems() {
335325       $total = 0;
  336326 
<> 337 -      if ($this->hasContents()) {
  338 -        foreach (array_keys($this->_contents) as $products_id) {
  339 -          $total += $this->getQuantity($products_id);
   327+      if ( $this->hasContents() ) {
   328+        foreach ( $this->_contents as $product ) {
   329+          $total += $this->getQuantity($product['id']);
340330         }
  341331       }
  342332 
  343333       return $total;
  344334     }
  345335 
<> 346 -    function getQuantity($products_id) {
  347 -      if (isset($this->_contents[$products_id])) {
  348 -        return $this->_contents[$products_id]['quantity'];
  349 -      }
  350 -
  351 -      return 0;
   336+    public function getQuantity($product_id) {
   337+      return ( isset($this->_contents[$product_id]) ) ? $this->_contents[$product_id]['quantity'] : 0;
352338     }
  353339 
<> 354 -    function exists($products_id) {
  355 -      return isset($this->_contents[$products_id]);
   340+    public function exists($product_id) {
   341+      return isset($this->_contents[$product_id]);
356342     }
  357343 
<> 358 -    function remove($products_id) {
   344+    public function remove($product_id) {
359345       global $osC_Database, $osC_Customer;
  360346 
<> 361 -      unset($this->_contents[$products_id]);
   347+      unset($this->_contents[$product_id]);
362348 
<> 363 -// remove from database
  364 -      if ($osC_Customer->isLoggedOn()) {
   349+      if ( $osC_Customer->isLoggedOn() ) {
365350         $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  366351         $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  367352         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
<> 368 -        $Qdelete->bindValue(':products_id', $products_id);
   353+        $Qdelete->bindInt(':products_id', $product_id);
369354         $Qdelete->execute();
  370355       }
  371356 
  372357       $this->_calculate();
  373358     }
  374359 
<> 375 -    function getProducts() {
   360+    public function getProducts() {
376361       static $_is_sorted = false;
  377362 
<> 378 -      if ($_is_sorted === false) {
   363+      if ( $_is_sorted === false ) {
379364         $_is_sorted = true;
  380365 
  381366         uasort($this->_contents, array('osC_ShoppingCart', '_uasortProductsByDateAdded'));
     
 !
384369       return $this->_contents;
  385370     }
  386371 
<> 387 -    function getSubTotal() {
   372+    public function getSubTotal() {
388373       return $this->_sub_total;
  389374     }
  390375 
<> 391 -    function getTotal() {
   376+    public function getTotal() {
392377       return $this->_total;
  393378     }
  394379 
<> 395 -    function getWeight() {
   380+    public function getWeight() {
396381       return $this->_weight;
  397382     }
  398383 
<> 399 -    function generateCartID($length = 5) {
   384+    public function generateCartID($length = 5) {
400385       return osc_create_random_string($length, 'digits');
  401386     }
  402387 
<> 403 -    function getCartID() {
   388+    public function getCartID() {
404389       return $_SESSION['cartID'];
  405390     }
  406391 
<> 407 -    function getContentType() {
   392+    public function getContentType() {
408393       global $osC_Database;
  409394 
  410395       $this->_content_type = 'physical';
  411396 
  412397       if ( (DOWNLOAD_ENABLED == '1') && $this->hasContents() ) {
<> 413 -        foreach ($this->_contents as $products_id => $data) {
   398+        foreach ( $this->_contents as $product_id => $data ) {
   399+/* HPDL
414400           if (isset($data['attributes'])) {
  415401             foreach ($data['attributes'] as $value) {
  416402               $Qcheck = $osC_Database->query('select count(*) as total from :table_products_attributes pa, :table_products_attributes_download pad where pa.products_id = :products_id and pa.options_values_id = :options_values_id and pa.products_attributes_id = pad.products_attributes_id');
     
 !
445431               }
  446432             }
  447433           } else {
<> 448 -            switch ($this->_content_type) {
   434+*/
   435+            switch ( $this->_content_type ) {
449436               case 'virtual':
  450437                 $this->_content_type = 'mixed';
  451438 
<> 452 -                return $this->_content_type;
  453 -                break;
   439+                break 2;
   440+
454441               default:
  455442                 $this->_content_type = 'physical';
<>  443+
456444                 break;
  457445             }
<> 458 -          }
   446+//          }
459447         }
  460448       }
  461449 
  462450       return $this->_content_type;
  463451     }
  464452 
<> 465 -    function hasAttributes($products_id) {
  466 -      return isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes']);
   453+    public function isVariant($id) {
   454+      return isset($this->_contents[$id]['variants']) && !empty($this->_contents[$id]['variants']);
467455     }
  468456 
<> 469 -    function getAttributes($products_id) {
  470 -      if (isset($this->_contents[$products_id]['attributes']) && !empty($this->_contents[$products_id]['attributes'])) {
  471 -        return $this->_contents[$products_id]['attributes'];
   457+    public function getVariant($id) {
   458+      if ( isset($this->_contents[$id]['variants']) && !empty($this->_contents[$id]['variants']) ) {
   459+        return $this->_contents[$id]['variants'];
472460       }
  473461     }
  474462 
<> 475 -    function isInStock($products_id) {
   463+    public function isInStock($product_id) {
476464       global $osC_Database;
  477465 
  478466       $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
  479467       $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
<> 480 -      $Qstock->bindInt(':products_id', osc_get_product_id($products_id));
   468+      $Qstock->bindInt(':products_id', $product_id);
481469       $Qstock->execute();
  482470 
<> 483 -      if (($Qstock->valueInt('products_quantity') - $this->_contents[$products_id]['quantity']) > 0) {
   471+      if ( ($Qstock->valueInt('products_quantity') - $this->_contents[$product_id]['quantity']) > 0 ) {
484472         return true;
<> 485 -      } elseif ($this->_products_in_stock === true) {
   473+      } elseif ( $this->_products_in_stock === true ) {
486474         $this->_products_in_stock = false;
  487475       }
  488476 
  489477       return false;
  490478     }
  491479 
<> 492 -    function hasStock() {
   480+    public function hasStock() {
493481       return $this->_products_in_stock;
  494482     }
  495483 
<> 496 -    function hasShippingAddress() {
  497 -      return isset($this->_shipping_address) && isset($this->_shipping_address['id']);
   484+    public function hasShippingAddress() {
   485+      return isset($this->_shipping_address['id']);
498486     }
  499487 
<> 500 -    function setShippingAddress($address_id) {
   488+    public function setShippingAddress($address_id) {
501489       global $osC_Database, $osC_Customer;
  502490 
<> 503 -      $previous_address = false;
   491+      $previous_address = null;
504492 
<> 505 -      if (isset($this->_shipping_address['id'])) {
   493+      if ( isset($this->_shipping_address['id']) ) {
506494         $previous_address = $this->getShippingAddress();
  507495       }
  508496 
     
 !
514502       $Qaddress->bindInt(':address_book_id', $address_id);
  515503       $Qaddress->execute();
  516504 
<> 517 -      $this->_shipping_address = array('id' => $address_id,
  518 -                                       'firstname' => $Qaddress->valueProtected('entry_firstname'),
  519 -                                       'lastname' => $Qaddress->valueProtected('entry_lastname'),
  520 -                                       'company' => $Qaddress->valueProtected('entry_company'),
  521 -                                       'street_address' => $Qaddress->valueProtected('entry_street_address'),
  522 -                                       'suburb' => $Qaddress->valueProtected('entry_suburb'),
  523 -                                       'city' => $Qaddress->valueProtected('entry_city'),
  524 -                                       'postcode' => $Qaddress->valueProtected('entry_postcode'),
  525 -                                       'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
  526 -                                       'zone_id' => $Qaddress->valueInt('entry_zone_id'),
  527 -                                       'zone_code' => $Qaddress->value('zone_code'),
  528 -                                       'country_id' => $Qaddress->valueInt('entry_country_id'),
  529 -                                       'country_title' => $Qaddress->value('countries_name'),
  530 -                                       'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),
  531 -                                       'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),
  532 -                                       'format' => $Qaddress->value('address_format'),
  533 -                                       'telephone_number' => $Qaddress->value('entry_telephone'));
   505+      if ( $Qaddress->numberOfRows() === 1 ) {
   506+        $this->_shipping_address = array('id' => $address_id,
   507+                                         'firstname' => $Qaddress->valueProtected('entry_firstname'),
   508+                                         'lastname' => $Qaddress->valueProtected('entry_lastname'),
   509+                                         'company' => $Qaddress->valueProtected('entry_company'),
   510+                                         'street_address' => $Qaddress->valueProtected('entry_street_address'),
   511+                                         'suburb' => $Qaddress->valueProtected('entry_suburb'),
   512+                                         'city' => $Qaddress->valueProtected('entry_city'),
   513+                                         'postcode' => $Qaddress->valueProtected('entry_postcode'),
   514+                                         'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
   515+                                         'zone_id' => $Qaddress->valueInt('entry_zone_id'),
   516+                                         'zone_code' => $Qaddress->value('zone_code'),
   517+                                         'country_id' => $Qaddress->valueInt('entry_country_id'),
   518+                                         'country_title' => $Qaddress->value('countries_name'),
   519+                                         'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),
   520+                                         'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),
   521+                                         'format' => $Qaddress->value('address_format'),
   522+                                         'telephone_number' => $Qaddress->value('entry_telephone'));
534523 
<> 535 -      if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_shipping_address['id']) || ($previous_address['country_id'] != $this->_shipping_address['country_id']) || ($previous_address['zone_id'] != $this->_shipping_address['zone_id']) || ($previous_address['state'] != $this->_shipping_address['state']) || ($previous_address['postcode'] != $this->_shipping_address['postcode']) ) ) {
  536 -        $this->_calculate();
   524+        if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_shipping_address['id']) || ($previous_address['country_id'] != $this->_shipping_address['country_id']) || ($previous_address['zone_id'] != $this->_shipping_address['zone_id']) || ($previous_address['state'] != $this->_shipping_address['state']) || ($previous_address['postcode'] != $this->_shipping_address['postcode']) ) ) {
   525+          $this->_calculate();
   526+        }
537527       }
  538528     }
  539529 
<> 540 -    function getShippingAddress($key = '') {
  541 -      if (empty($key)) {
   530+    public function getShippingAddress($key = null) {
   531+      if ( empty($key) ) {
542532         return $this->_shipping_address;
  543533       }
  544534 
  545535       return $this->_shipping_address[$key];
  546536     }
  547537 
<> 548 -    function resetShippingAddress() {
   538+    public function resetShippingAddress() {
549539       global $osC_Customer;
  550540 
<> 551 -      $this->_shipping_address = array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY);
   541+      $this->_shipping_address = array('zone_id' => STORE_ZONE,
   542+                                       'country_id' => STORE_COUNTRY);
552543 
<> 553 -      if ($osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress()) {
   544+      if ( $osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress() ) {
554545         $this->setShippingAddress($osC_Customer->getDefaultAddressID());
  555546       }
  556547     }
  557548 
<> 558 -    function setShippingMethod($shipping_array, $calculate_total = true) {
   549+    public function setShippingMethod($shipping_array, $calculate_total = true) {
559550       $this->_shipping_method = $shipping_array;
  560551 
<> 561 -      if ($calculate_total === true) {
   552+      if ( $calculate_total === true ) {
562553         $this->_calculate(false);
  563554       }
  564555     }
  565556 
<> 566 -    function getShippingMethod($key = '') {
  567 -      if (empty($key)) {
   557+    public function getShippingMethod($key = null) {
   558+      if ( empty($key) ) {
568559         return $this->_shipping_method;
  569560       }
  570561 
  571562       return $this->_shipping_method[$key];
  572563     }
  573564 
<> 574 -    function resetShippingMethod() {
   565+    public function resetShippingMethod() {
575566       $this->_shipping_method = array();
  576567 
  577568       $this->_calculate();
  578569     }
  579570 
<> 580 -    function hasShippingMethod() {
   571+    public function hasShippingMethod() {
581572       return !empty($this->_shipping_method);
  582573     }
  583574 
<> 584 -    function hasBillingAddress() {
  585 -      return isset($this->_billing_address) && isset($this->_billing_address['id']);
   575+    public function hasBillingAddress() {
   576+      return isset($this->_billing_address['id']);
586577     }
  587578 
<> 588 -    function setBillingAddress($address_id) {
   579+    public function setBillingAddress($address_id) {
589580       global $osC_Database, $osC_Customer;
  590581 
  591582       $previous_address = false;
  592583 
<> 593 -      if (isset($this->_billing_address['id'])) {
   584+      if ( isset($this->_billing_address['id']) ) {
594585         $previous_address = $this->getBillingAddress();
  595586       }
  596587 
     
 !
602593       $Qaddress->bindInt(':address_book_id', $address_id);
  603594       $Qaddress->execute();
  604595 
<> 605 -      $this->_billing_address = array('id' => $address_id,
  606 -                                      'firstname' => $Qaddress->valueProtected('entry_firstname'),
  607 -                                      'lastname' => $Qaddress->valueProtected('entry_lastname'),
  608 -                                      'company' => $Qaddress->valueProtected('entry_company'),
  609 -                                      'street_address' => $Qaddress->valueProtected('entry_street_address'),
  610 -                                      'suburb' => $Qaddress->valueProtected('entry_suburb'),
  611 -                                      'city' => $Qaddress->valueProtected('entry_city'),
  612 -                                      'postcode' => $Qaddress->valueProtected('entry_postcode'),
  613 -                                      'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
  614 -                                      'zone_id' => $Qaddress->valueInt('entry_zone_id'),
  615 -                                      'zone_code' => $Qaddress->value('zone_code'),
  616 -                                      'country_id' => $Qaddress->valueInt('entry_country_id'),
  617 -                                      'country_title' => $Qaddress->value('countries_name'),
  618 -                                      'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),
  619 -                                      'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),
  620 -                                      'format' => $Qaddress->value('address_format'),
  621 -                                      'telephone_number' => $Qaddress->value('entry_telephone'));
   596+      if ( $Qaddress->numberOfRows() === 1 ) {
   597+        $this->_billing_address = array('id' => $address_id,
   598+                                        'firstname' => $Qaddress->valueProtected('entry_firstname'),
   599+                                        'lastname' => $Qaddress->valueProtected('entry_lastname'),
   600+                                        'company' => $Qaddress->valueProtected('entry_company'),
   601+                                        'street_address' => $Qaddress->valueProtected('entry_street_address'),
   602+                                        'suburb' => $Qaddress->valueProtected('entry_suburb'),
   603+                                        'city' => $Qaddress->valueProtected('entry_city'),
   604+                                        'postcode' => $Qaddress->valueProtected('entry_postcode'),
   605+                                        'state' => (!osc_empty($Qaddress->valueProtected('entry_state'))) ? $Qaddress->valueProtected('entry_state') : $Qaddress->valueProtected('zone_name'),
   606+                                        'zone_id' => $Qaddress->valueInt('entry_zone_id'),
   607+                                        'zone_code' => $Qaddress->value('zone_code'),
   608+                                        'country_id' => $Qaddress->valueInt('entry_country_id'),
   609+                                        'country_title' => $Qaddress->value('countries_name'),
   610+                                        'country_iso_code_2' => $Qaddress->value('countries_iso_code_2'),
   611+                                        'country_iso_code_3' => $Qaddress->value('countries_iso_code_3'),
   612+                                        'format' => $Qaddress->value('address_format'),
   613+                                        'telephone_number' => $Qaddress->value('entry_telephone'));
622614 
<> 623 -      if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_billing_address['id']) || ($previous_address['country_id'] != $this->_billing_address['country_id']) || ($previous_address['zone_id'] != $this->_billing_address['zone_id']) || ($previous_address['state'] != $this->_billing_address['state']) || ($previous_address['postcode'] != $this->_billing_address['postcode']) ) ) {
  624 -        $this->_calculate();
   615+        if ( is_array($previous_address) && ( ($previous_address['id'] != $this->_billing_address['id']) || ($previous_address['country_id'] != $this->_billing_address['country_id']) || ($previous_address['zone_id'] != $this->_billing_address['zone_id']) || ($previous_address['state'] != $this->_billing_address['state']) || ($previous_address['postcode'] != $this->_billing_address['postcode']) ) ) {
   616+          $this->_calculate();
   617+        }
625618       }
  626619     }
  627620 
<> 628 -    function getBillingAddress($key = '') {
  629 -      if (empty($key)) {
   621+    public function getBillingAddress($key = null) {
   622+      if ( empty($key) ) {
630623         return $this->_billing_address;
  631624       }
  632625 
  633626       return $this->_billing_address[$key];
  634627     }
  635628 
<> 636 -    function resetBillingAddress() {
   629+    public function resetBillingAddress() {
637630       global $osC_Customer;
  638631 
<> 639 -      $this->_billing_address = array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY);
   632+      $this->_billing_address = array('zone_id' => STORE_ZONE,
   633+                                      'country_id' => STORE_COUNTRY);
640634 
<> 641 -      if ($osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress()) {
   635+      if ( $osC_Customer->isLoggedOn() && $osC_Customer->hasDefaultAddress() ) {
642636         $this->setBillingAddress($osC_Customer->getDefaultAddressID());
  643637       }
  644638     }
  645639 
<> 646 -    function setBillingMethod($billing_array) {
   640+    public function setBillingMethod($billing_array) {
647641       $this->_billing_method = $billing_array;
  648642 
  649643       $this->_calculate();
  650644     }
  651645 
<> 652 -    function getBillingMethod($key = '') {
  653 -      if (empty($key)) {
   646+    public function getBillingMethod($key = null) {
   647+      if ( empty($key) ) {
654648         return $this->_billing_method;
  655649       }
  656650 
  657651       return $this->_billing_method[$key];
  658652     }
  659653 
<> 660 -    function resetBillingMethod() {
   654+    public function resetBillingMethod() {
661655       $this->_billing_method = array();
  662656 
  663657       $this->_calculate();
  664658     }
  665659 
<> 666 -    function hasBillingMethod() {
   660+    public function hasBillingMethod() {
667661       return !empty($this->_billing_method);
  668662     }
  669663 
<> 670 -    function getTaxingAddress($id = '') {
  671 -      if ($this->getContentType() == 'virtual') {
   664+    public function getTaxingAddress($id = null) {
   665+      if ( $this->getContentType() == 'virtual' ) {
672666         return $this->getBillingAddress($id);
  673667       }
  674668 
  675669       return $this->getShippingAddress($id);
  676670     }
  677671 
<> 678 -    function addTaxAmount($amount) {
   672+    public function addTaxAmount($amount) {
679673       $this->_tax += $amount;
  680674     }
  681675 
<> 682 -    function numberOfTaxGroups() {
   676+    public function numberOfTaxGroups() {
683677       return sizeof($this->_tax_groups);
  684678     }
  685679 
<> 686 -    function addTaxGroup($group, $amount) {
  687 -      if (isset($this->_tax_groups[$group])) {
   680+    public function addTaxGroup($group, $amount) {
   681+      if ( isset($this->_tax_groups[$group]) ) {
688682         $this->_tax_groups[$group] += $amount;
  689683       } else {
  690684         $this->_tax_groups[$group] = $amount;
  691685       }
  692686     }
  693687 
<> 694 -    function addToTotal($amount) {
   688+    public function getTaxGroups() {
   689+      return $this->_tax_groups;
   690+    }
   691+
   692+    public function addToTotal($amount) {
695693       $this->_total += $amount;
  696694     }
  697695 
<> 698 -    function getOrderTotals() {
   696+    public function getOrderTotals() {
699697       return $this->_order_totals;
  700698     }
  701699 
<> 702 -    function getShippingBoxesWeight() {
   700+    public function getShippingBoxesWeight() {
703701       return $this->_shipping_boxes_weight;
  704702     }
  705703 
<> 706 -    function numberOfShippingBoxes() {
   704+    public function numberOfShippingBoxes() {
707705       return $this->_shipping_boxes;
  708706     }
  709707 
<> 710 -    function _cleanUp() {
   708+    private function _cleanUp() {
711709       global $osC_Database, $osC_Customer;
  712710 
<> 713 -      foreach ($this->_contents as $product_id_string => $data) {
  714 -        if ($data['quantity'] < 1) {
  715 -          unset($this->_contents[$product_id_string]);
   711+      foreach ( $this->_contents as $product_id => $data ) {
   712+        if ( $data['quantity'] < 1 ) {
   713+          unset($this->_contents[$product_id]);
716714 
<> 717 -// remove from database
  718 -          if ($osC_Customer->isLoggedOn()) {
   715+          if ( $osC_Customer->isLoggedOn() ) {
719716             $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  720717             $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  721718             $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
<> 722 -            $Qdelete->bindValue(':products_id', $product_id_string);
   719+            $Qdelete->bindValue(':products_id', $product_id);
723720             $Qdelete->execute();
  724721           }
  725722         }
  726723       }
  727724     }
  728725 
<> 729 -    function _calculate($set_shipping = true) {
   726+    private function _calculate($set_shipping = true) {
730727       global $osC_Currencies, $osC_Tax, $osC_Weight, $osC_Shipping, $osC_OrderTotal;
  731728 
  732729       $this->_sub_total = 0;
     
 !
741738 
  742739       $_SESSION['cartID'] = $this->generateCartID();
  743740 
<> 744 -      if ($this->hasContents()) {
  745 -        foreach ($this->_contents as $data) {
   741+      if ( $this->hasContents() ) {
   742+        foreach ( $this->_contents as $data ) {
746743           $products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT);
  747744           $this->_weight += $products_weight * $data['quantity'];
  748745 
  749746           $tax = $osC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
  750747           $tax_description = $osC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
  751748 
<> 752 -          $shown_price = $osC_Currencies->addTaxRateToPrice($data['final_price'], $tax, $data['quantity']);
   749+          $shown_price = $osC_Currencies->addTaxRateToPrice($data['price'], $tax, $data['quantity']);
753750 
  754751           $this->_sub_total += $shown_price;
  755752           $this->_total += $shown_price;
  756753 
<> 757 -          if (DISPLAY_PRICE_WITH_TAX == '1') {
   754+          if ( DISPLAY_PRICE_WITH_TAX == '1' ) {
758755             $tax_amount = $shown_price - ($shown_price / (($tax < 10) ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax)));
  759756           } else {
  760757             $tax_amount = ($tax / 100) * $shown_price;
     
 !
764761 
  765762           $this->_tax += $tax_amount;
  766763 
<> 767 -          if (isset($this->_tax_groups[$tax_description])) {
   764+          if ( isset($this->_tax_groups[$tax_description]) ) {
768765             $this->_tax_groups[$tax_description] += $tax_amount;
  769766           } else {
  770767             $this->_tax_groups[$tax_description] = $tax_amount;
     
 !
774771         $this->_shipping_boxes_weight = $this->_weight;
  775772         $this->_shipping_boxes = 1;
  776773 
<> 777 -        if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100)) {
   774+        if ( SHIPPING_BOX_WEIGHT >= ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100) ) {
778775           $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT;
  779776         } else {
  780777           $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + ($this->_shipping_boxes_weight * SHIPPING_BOX_PADDING/100);
  781778         }
  782779 
<> 783 -        if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
   780+        if ( $this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT ) { // Split into many boxes
784781           $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT);
  785782           $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes;
  786783         }
  787784 
<> 788 -        if ($set_shipping === true) {
  789 -          if (!class_exists('osC_Shipping')) {
   785+        if ( $set_shipping === true ) {
   786+          if ( !class_exists('osC_Shipping') ) {
790787             include('includes/classes/shipping.php');
  791788           }
  792789 
<> 793 -          if (!$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true)) {
   790+          if ( !$this->hasShippingMethod() || ($this->getShippingMethod('is_cheapest') === true) ) {
794791             $osC_Shipping = new osC_Shipping();
  795792             $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false);
  796793           } else {
     
 !
799796           }
  800797         }
  801798 
<> 802 -        if (!class_exists('osC_OrderTotal')) {
   799+        if ( !class_exists('osC_OrderTotal') ) {
803800           include('includes/classes/order_total.php');
  804801         }
  805802 
     
 !
808805       }
  809806     }
  810807 
<> 811 -    function _uasortProductsByDateAdded($a, $b) {
   808+    static private function _uasortProductsByDateAdded($a, $b) {
<_ 812809       if ($a['date_added'] == $b['date_added']) {
  813810         return strnatcasecmp($a['name'], $b['name']);
  814811       }