Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1674
 
1677
 
1677
 
shopping_cart.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shopping_cart.php 1674 2007-08-20 22:56:00Z hpdl $
   3+  $Id: shopping_cart.php 1677 2007-08-29 00:33:19Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
3232                                                    'tax_groups' => array(),
  3333                                                    'shipping_boxes_weight' => 0,
  3434                                                    'shipping_boxes' => 1,
<> 35 -                                                   'shipping_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY),
   35+                                                   'shipping_address' => array('zone_id' => STORE_ZONE,
   36+                                                                               'country_id' => STORE_COUNTRY),
3637                                                    'shipping_method' => array(),
<> 37 -                                                   'billing_address' => array('zone_id' => STORE_ZONE, 'country_id' => STORE_COUNTRY),
   38+                                                   'billing_address' => array('zone_id' => STORE_ZONE,
   39+                                                                              'country_id' => STORE_COUNTRY),
3840                                                    'billing_method' => array(),
  3941                                                    'shipping_quotes' => array(),
  4042                                                    'order_totals' => array());
     
 !
5961       $this->_order_totals =& $_SESSION['osC_ShoppingCart_data']['order_totals'];
  6062     }
  6163 
<> 62 -    public function update() {
   64+    public function refresh() {
6365       if ( !isset($_SESSION['cartID']) ) {
  6466         $this->_calculate();
  6567       }
     
 !
7678         return false;
  7779       }
  7880 
<> 79 -// insert current cart contents in database
  80 -      if ( $this->hasContents() ) {
  81 -        foreach ( $this->_contents as $product_id => $data ) {
  82 -          $Qproduct = $osC_Database->query('select products_id, customers_basket_quantity from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  83 -          $Qproduct->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   81+      foreach ( $this->_contents as $item_id => $data ) {
   82+        $db_action = 'check';
   83+
   84+        if ( isset($data['variants']) ) {
   85+          foreach ( $data['variants'] as $variant ) {
   86+            if ( $variant['has_custom_value'] === true ) {
   87+              $db_action = 'insert';
   88+
   89+              break;
   90+            }
   91+          }
   92+        }
   93+
   94+        if ( $db_action == 'check' ) {
   95+          $Qproduct = $osC_Database->query('select item_id, quantity from :table_shopping_carts where customers_id = :customers_id and products_id = :products_id');
   96+          $Qproduct->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
8497           $Qproduct->bindInt(':customers_id', $osC_Customer->getID());
<> 85 -          $Qproduct->bindInt(':products_id', $product_id);
   98+          $Qproduct->bindInt(':products_id', $data['id']);
8699           $Qproduct->execute();
  87100 
  88101           if ( $Qproduct->numberOfRows() > 0 ) {
<> 89 -            $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');
  90 -            $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  91 -            $Qupdate->bindInt(':customers_basket_quantity', $data['quantity'] + $Qproduct->valueInt('customers_basket_quantity'));
   102+            $Qupdate = $osC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
   103+            $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   104+            $Qupdate->bindInt(':quantity', $data['quantity'] + $Qproduct->valueInt('quantity'));
92105             $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
<> 93 -            $Qupdate->bindInt(':products_id', $product_id);
   106+            $Qupdate->bindInt(':item_id', $Qproduct->valueInt('item_id'));
94107             $Qupdate->execute();
  95108           } else {
<> 96 -            $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())');
  97 -            $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  98 -            $Qnew->bindInt(':customers_id', $osC_Customer->getID());
  99 -            $Qnew->bindValue(':products_id', $product_id);
  100 -            $Qnew->bindInt(':customers_basket_quantity', $data['quantity']);
  101 -            $Qnew->execute();
   109+            $db_action = 'insert';
102110           }
  103111         }
<>  112+
   113+        if ( $db_action == 'insert') {
   114+          $Qid = $osC_Database->query('select max(item_id) as item_id from :table_shopping_carts where customers_id = :customers_id');
   115+          $Qid->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   116+          $Qid->bindInt(':customers_id', $osC_Customer->getID());
   117+          $Qid->execute();
   118+
   119+          $db_item_id = $Qid->valueInt('item_id') + 1;
   120+
   121+          $Qnew = $osC_Database->query('insert into :table_shopping_carts (customers_id, item_id, products_id, quantity, date_added) values (:customers_id, :item_id, :products_id, :quantity, :date_added)');
   122+          $Qnew->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   123+          $Qnew->bindInt(':customers_id', $osC_Customer->getID());
   124+          $Qnew->bindInt(':item_id', $db_item_id);
   125+          $Qnew->bindInt(':products_id', $data['id']);
   126+          $Qnew->bindInt(':quantity', $data['quantity']);
   127+          $Qnew->bindRaw(':date_added', 'now()');
   128+          $Qnew->execute();
   129+
   130+          if ( isset($data['variants']) ) {
   131+            foreach ( $data['variants'] as $variant ) {
   132+              if ( $variant['has_custom_value'] === true ) {
   133+                $Qnew = $osC_Database->query('insert into :table_shopping_carts_custom_variants_values (shopping_carts_item_id, customers_id, products_id, products_variants_values_id, products_variants_values_text) values (:shopping_carts_item_id, :customers_id, :products_id, :products_variants_values_id, :products_variants_values_text)');
   134+                $Qnew->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   135+                $Qnew->bindInt(':shopping_carts_item_id', $db_item_id);
   136+                $Qnew->bindInt(':customers_id', $osC_Customer->getID());
   137+                $Qnew->bindInt(':products_id', $data['id']);
   138+                $Qnew->bindInt(':products_variants_values_id', $variant['value_id']);
   139+                $Qnew->bindValue(':products_variants_values_text', $variant['value_title']);
   140+                $Qnew->execute();
   141+              }
   142+            }
   143+          }
   144+        }
104145       }
  105146 
  106147 // reset per-session cart contents, but not the database contents
  107148       $this->reset();
  108149 
  109150       $_delete_array = array();
  110151 
<> 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');
  112 -      $Qproducts->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   152+      $Qproducts = $osC_Database->query('select sc.item_id, sc.products_id, sc.quantity, sc.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_shopping_carts sc, :table_products p where sc.customers_id = :customers_id and sc.products_id = p.products_id order by sc.date_added desc');
   153+      $Qproducts->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
113154       $Qproducts->bindTable(':table_products', TABLE_PRODUCTS);
  114155       $Qproducts->bindInt(':customers_id', $osC_Customer->getID());
  115156       $Qproducts->execute();
     
 !
136177             }
  137178           }
  138179 
<> 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'));
   180+          $this->_contents[$Qproducts->valueInt('item_id')] = array('item_id' => $Qproducts->valueInt('item_id'),
   181+                                                                    'id' => $Qproducts->valueInt('products_id'),
   182+                                                                    'parent_id' => $Qproducts->valueInt('parent_id'),
   183+                                                                    'name' => $Qdesc->value('products_name'),
   184+                                                                    'keyword' => $Qdesc->value('products_keyword'),
   185+                                                                    'image' => ($Qimage->numberOfRows() === 1) ? $Qimage->value('image') : '',
   186+                                                                    'price' => $price,
   187+                                                                    'quantity' => $Qproducts->valueInt('quantity'),
   188+                                                                    'weight' => $Qproducts->value('products_weight'),
   189+                                                                    'tax_class_id' => $Qproducts->valueInt('products_tax_class_id'),
   190+                                                                    'date_added' => osC_DateTime::getShort($Qproducts->value('date_added')),
   191+                                                                    'weight_class_id' => $Qproducts->valueInt('products_weight_class'));
150192 
  151193           if ( $Qproducts->valueInt('parent_id') > 0 ) {
  152194             $Qcheck = $osC_Database->query('select products_status from :table_products where products_id = :products_id');
     
 !
155197             $Qcheck->execute();
  156198 
  157199             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');
   200+              $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvg.module, 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');
159201               $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
  160202               $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
  161203               $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
     
 !
164206               $Qvariant->bindInt(':languages_id', $osC_Language->getID());
  165207               $Qvariant->execute();
  166208 
<> 167 -              if ( $Qproducts->numberOfRows() > 0 ) {
   209+              if ( $Qvariant->numberOfRows() > 0 ) {
168210                 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'));
   211+                  $group_title = osC_Variants::getGroupTitle($Qvariant->value('module'), $Qvariant->toArray());
   212+                  $value_title = $Qvariant->value('value_title');
   213+                  $has_custom_value = false;
   214+
   215+                  $Qcvv = $osC_Database->query('select products_variants_values_text from :table_shopping_carts_custom_variants_values where customers_id = :customers_id and shopping_carts_item_id = :shopping_carts_item_id and products_id = :products_id and products_variants_values_id = :products_variants_values_id');
   216+                  $Qcvv->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   217+                  $Qcvv->bindInt(':customers_id', $osC_Customer->getID());
   218+                  $Qcvv->bindInt(':shopping_carts_item_id', $Qproducts->valueInt('item_id'));
   219+                  $Qcvv->bindInt(':products_id', $Qproducts->valueInt('products_id'));
   220+                  $Qcvv->bindInt(':products_variants_values_id', $Qvariant->valueInt('value_id'));
   221+                  $Qcvv->execute();
   222+
   223+                  if ( $Qcvv->numberOfRows() === 1 ) {
   224+                    $value_title = $Qcvv->value('products_variants_values_text');
   225+                    $has_custom_value = true;
   226+                  }
   227+
   228+                  $this->_contents[$Qproducts->valueInt('item_id')]['variants'][] = array('group_id' => $Qvariant->valueInt('group_id'),
   229+                                                                                          'value_id' => $Qvariant->valueInt('value_id'),
   230+                                                                                          'group_title' => $group_title,
   231+                                                                                          'value_title' => $value_title,
   232+                                                                                          'has_custom_value' => $has_custom_value);
173233                 }
  174234               } else {
<> 175 -                $_delete_array[] = $Qproducts->valueInt('products_id');
   235+                $_delete_array[] = $Qproducts->valueInt('item_id');
176236               }
  177237             } else {
<> 178 -              $_delete_array[] = $Qproducts->valueInt('products_id');
   238+              $_delete_array[] = $Qproducts->valueInt('item_id');
179239             }
  180240           }
  181241         } else {
<> 182 -          $_delete_array[] = $Qproducts->valueInt('products_id');
   242+          $_delete_array[] = $Qproducts->valueInt('item_id');
183243         }
  184244       }
  185245 
  186246       if ( !empty($_delete_array) ) {
<> 187 -        foreach ( $_delete_array as $product_id ) {
  188 -          unset($this->_contents[$product_id]);
   247+        foreach ( $_delete_array as $id ) {
   248+          unset($this->_contents[$id]);
189249         }
  190250 
<> 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);
   251+        $Qdelete = $osC_Database->query('delete from :table_shopping_carts where customers_id = :customers_id and item_id in (":item_id")');
   252+        $Qdelete->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
193253         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
<> 194 -        $Qdelete->bindRaw(':products_id', implode('", "', $_delete_array));
   254+        $Qdelete->bindRaw(':item_id', implode('", "', $_delete_array));
195255         $Qdelete->execute();
<>  256+
   257+        $Qdelete = $osC_Database->query('delete from :table_shopping_carts_custom_variants_values where customers_id = :customers_id and shopping_carts_item_id in (":shopping_carts_item_id")');
   258+        $Qdelete->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   259+        $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
   260+        $Qdelete->bindRaw(':shopping_carts_item_id', implode('", "', $_delete_array));
   261+        $Qdelete->execute();
196262       }
  197263 
  198264       $this->_cleanUp();
     
 !
203269       global $osC_Database, $osC_Customer;
  204270 
  205271       if ( ($reset_database === true) && $osC_Customer->isLoggedOn() ) {
<> 206 -        $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id');
  207 -        $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   272+        $Qdelete = $osC_Database->query('delete from :table_shopping_carts where customers_id = :customers_id');
   273+        $Qdelete->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
208274         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
  209275         $Qdelete->execute();
<>  276+
   277+        $Qdelete = $osC_Database->query('delete from :table_shopping_carts_custom_variants_values where customers_id = :customers_id');
   278+        $Qdelete->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   279+        $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
   280+        $Qdelete->execute();
210281       }
  211282 
  212283       $this->_contents = array();
     
 !
240311 
  241312         if ( $Qproduct->valueInt('products_status') === 1 ) {
  242313           if ( $this->exists($product_id) ) {
<>  314+            $item_id = $this->getBasketID($product_id);
   315+
243316             if ( !is_numeric($quantity) ) {
<> 244 -              $quantity = $this->getQuantity($product_id) + 1;
   317+              $quantity = $this->getQuantity($item_id) + 1;
245318             }
  246319 
<> 247 -            $this->_contents[$product_id]['quantity'] = $quantity;
   320+            $this->_contents[$item_id]['quantity'] = $quantity;
248321 
  249322             if ( $osC_Customer->isLoggedOn() ) {
<> 250 -              $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');
  251 -              $Qupdate->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
  252 -              $Qupdate->bindInt(':customers_basket_quantity', $quantity);
   323+              $Qupdate = $osC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
   324+              $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   325+              $Qupdate->bindInt(':quantity', $quantity);
253326               $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
<> 254 -              $Qupdate->bindInt(':products_id', $product_id);
   327+              $Qupdate->bindInt(':item_id', $item_id);
255328               $Qupdate->execute();
  256329             }
  257330           } else {
     
 !
275348               }
  276349             }
  277350 
<> 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'));
   351+            if ( $osC_Customer->isLoggedOn() ) {
   352+              $Qid = $osC_Database->query('select max(item_id) as item_id from :table_shopping_carts where customers_id = :customers_id');
   353+              $Qid->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   354+              $Qid->bindInt(':customers_id', $osC_Customer->getID());
   355+              $Qid->execute();
289356 
<>  357+              $item_id = $Qid->valueInt('item_id') + 1;
   358+            } else {
   359+              $item_id = max(array_keys($this->_contents)) + 1;
   360+            }
   361+
   362+            $this->_contents[$item_id] = array('item_id' => $item_id,
   363+                                               'id' => $product_id,
   364+                                               'parent_id' => $Qproduct->valueInt('parent_id'),
   365+                                               'name' => $Qdescription->value('products_name'),
   366+                                               'keyword' => $Qdescription->value('products_keyword'),
   367+                                               'image' => $Qproduct->value('image'),
   368+                                               'price' => $price,
   369+                                               'quantity' => $quantity,
   370+                                               'weight' => $Qproduct->value('products_weight'),
   371+                                               'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'),
   372+                                               'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()),
   373+                                               'weight_class_id' => $Qproduct->valueInt('products_weight_class'));
   374+
290375             if ( $osC_Customer->isLoggedOn() ) {
<> 291 -              $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())');
  292 -              $Qnew->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   376+              $Qnew = $osC_Database->query('insert into :table_shopping_carts (customers_id, item_id, products_id, quantity, date_added) values (:customers_id, :item_id, :products_id, :quantity, :date_added)');
   377+              $Qnew->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
293378               $Qnew->bindInt(':customers_id', $osC_Customer->getID());
<>  379+              $Qnew->bindInt(':item_id', $item_id);
294380               $Qnew->bindInt(':products_id', $product_id);
<> 295 -              $Qnew->bindInt(':customers_basket_quantity', $quantity);
   381+              $Qnew->bindInt(':quantity', $quantity);
   382+              $Qnew->bindRaw(':date_added', 'now()');
296383               $Qnew->execute();
  297384             }
  298385 
  299386             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');
   387+              $Qvariant = $osC_Database->query('select pvg.id as group_id, pvg.title as group_title, pvg.module, 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');
301388               $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
  302389               $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
  303390               $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
     
 !
307394               $Qvariant->execute();
  308395 
  309396               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'));
   397+                $group_title = osC_Variants::getGroupTitle($Qvariant->value('module'), $Qvariant->toArray());
   398+                $value_title = osC_Variants::getValueTitle($Qvariant->value('module'), $Qvariant->toArray());
   399+                $has_custom_value = osC_Variants::hasCustomValue($Qvariant->value('module'));
   400+
   401+                $this->_contents[$item_id]['variants'][] = array('group_id' => $Qvariant->valueInt('group_id'),
   402+                                                                 'value_id' => $Qvariant->valueInt('value_id'),
   403+                                                                 'group_title' => $group_title,
   404+                                                                 'value_title' => $value_title,
   405+                                                                 'has_custom_value' => $has_custom_value);
   406+
   407+                if ( $osC_Customer->isLoggedOn() && ($has_custom_value === true) ) {
   408+                  $Qnew = $osC_Database->query('insert into :table_shopping_carts_custom_variants_values (shopping_carts_item_id, customers_id, products_id, products_variants_values_id, products_variants_values_text) values (:shopping_carts_item_id, :customers_id, :products_id, :products_variants_values_id, :products_variants_values_text)');
   409+                  $Qnew->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   410+                  $Qnew->bindInt(':shopping_carts_item_id', $item_id);
   411+                  $Qnew->bindInt(':customers_id', $osC_Customer->getID());
   412+                  $Qnew->bindInt(':products_id', $product_id);
   413+                  $Qnew->bindInt(':products_variants_values_id', $Qvariant->valueInt('value_id'));
   414+                  $Qnew->bindValue(':products_variants_values_text', $value_title);
   415+                  $Qnew->execute();
   416+                }
314417               }
  315418             }
  316419           }
     
 !
324427     public function numberOfItems() {
  325428       $total = 0;
  326429 
<> 327 -      if ( $this->hasContents() ) {
  328 -        foreach ( $this->_contents as $product ) {
  329 -          $total += $this->getQuantity($product['id']);
  330 -        }
   430+      foreach ( $this->_contents as $product ) {
   431+        $total += $product['quantity'];
331432       }
  332433 
  333434       return $total;
  334435     }
  335436 
<> 336 -    public function getQuantity($product_id) {
  337 -      return ( isset($this->_contents[$product_id]) ) ? $this->_contents[$product_id]['quantity'] : 0;
   437+    public function getBasketID($product_id) {
   438+      foreach ( $this->_contents as $item_id => $product ) {
   439+        if ( $product['id'] === $product_id ) {
   440+          return $item_id;
   441+        }
   442+      }
338443     }
  339444 
<>  445+    public function getQuantity($item_id) {
   446+      return ( isset($this->_contents[$item_id]) ) ? $this->_contents[$item_id]['quantity'] : 0;
   447+    }
   448+
340449     public function exists($product_id) {
<> 341 -      return isset($this->_contents[$product_id]);
   450+      foreach ( $this->_contents as $product ) {
   451+        if ( $product['id'] === $product_id ) {
   452+          if ( isset($product['variants']) ) {
   453+            foreach ( $product['variants'] as $variant ) {
   454+              if ( $variant['has_custom_value'] === true ) {
   455+                return false;
   456+              }
   457+            }
   458+          }
   459+
   460+          return true;
   461+        }
   462+      }
   463+
   464+      return false;
342465     }
  343466 
<> 344 -    public function remove($product_id) {
   467+    public function update($item_id, $quantity) {
345468       global $osC_Database, $osC_Customer;
  346469 
<> 347 -      unset($this->_contents[$product_id]);
   470+      if ( !is_numeric($quantity) ) {
   471+        $quantity = $this->getQuantity($item_id) + 1;
   472+      }
348473 
<>  474+      $this->_contents[$item_id]['quantity'] = $quantity;
   475+
349476       if ( $osC_Customer->isLoggedOn() ) {
<> 350 -        $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  351 -        $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   477+        $Qupdate = $osC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
   478+        $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   479+        $Qupdate->bindInt(':quantity', $quantity);
   480+        $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
   481+        $Qupdate->bindInt(':item_id', $item_id);
   482+        $Qupdate->execute();
   483+      }
   484+
   485+      $this->_cleanUp();
   486+      $this->_calculate();
   487+    }
   488+
   489+    public function remove($item_id) {
   490+      global $osC_Database, $osC_Customer;
   491+
   492+      unset($this->_contents[$item_id]);
   493+
   494+      if ( $osC_Customer->isLoggedOn() ) {
   495+        $Qdelete = $osC_Database->query('delete from :table_shopping_carts where customers_id = :customers_id and item_id = :item_id');
   496+        $Qdelete->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
352497         $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
<> 353 -        $Qdelete->bindInt(':products_id', $product_id);
   498+        $Qdelete->bindInt(':item_id', $item_id);
354499         $Qdelete->execute();
<>  500+
   501+        $Qdelete = $osC_Database->query('delete from :table_shopping_carts_custom_variants_values where customers_id = :customers_id and shopping_carts_item_id = :shopping_carts_item_id');
   502+        $Qdelete->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   503+        $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
   504+        $Qdelete->bindInt(':shopping_carts_item_id', $item_id);
   505+        $Qdelete->execute();
355506       }
  356507 
  357508       $this->_calculate();
     
 !
450601       return $this->_content_type;
  451602     }
  452603 
<> 453 -    public function isVariant($id) {
  454 -      return isset($this->_contents[$id]['variants']) && !empty($this->_contents[$id]['variants']);
   604+    public function isVariant($item_id) {
   605+      return isset($this->_contents[$item_id]['variants']) && !empty($this->_contents[$item_id]['variants']);
455606     }
  456607 
<> 457 -    public function getVariant($id) {
  458 -      if ( isset($this->_contents[$id]['variants']) && !empty($this->_contents[$id]['variants']) ) {
  459 -        return $this->_contents[$id]['variants'];
   608+    public function getVariant($item_id) {
   609+      if ( isset($this->_contents[$item_id]['variants']) && !empty($this->_contents[$item_id]['variants']) ) {
   610+        return $this->_contents[$item_id]['variants'];
460611       }
  461612     }
  462613 
<> 463 -    public function isInStock($product_id) {
   614+    public function isInStock($item_id) {
464615       global $osC_Database;
  465616 
  466617       $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
  467618       $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
<> 468 -      $Qstock->bindInt(':products_id', $product_id);
   619+      $Qstock->bindInt(':products_id', $this->_contents[$item_id]['id']);
469620       $Qstock->execute();
  470621 
<> 471 -      if ( ($Qstock->valueInt('products_quantity') - $this->_contents[$product_id]['quantity']) > 0 ) {
   622+      if ( ($Qstock->valueInt('products_quantity') - $this->_contents[$item_id]['quantity']) > 0 ) {
472623         return true;
  473624       } elseif ( $this->_products_in_stock === true ) {
  474625         $this->_products_in_stock = false;
     
 !
708859     private function _cleanUp() {
  709860       global $osC_Database, $osC_Customer;
  710861 
<> 711 -      foreach ( $this->_contents as $product_id => $data ) {
   862+      foreach ( $this->_contents as $item_id => $data ) {
712863         if ( $data['quantity'] < 1 ) {
<> 713 -          unset($this->_contents[$product_id]);
   864+          unset($this->_contents[$item_id]);
714865 
  715866           if ( $osC_Customer->isLoggedOn() ) {
<> 716 -            $Qdelete = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id and products_id = :products_id');
  717 -            $Qdelete->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
   867+            $Qdelete = $osC_Database->query('delete from :table_shopping_carts where customers_id = :customers_id and item_id = :item_id');
   868+            $Qdelete->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
718869             $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
<> 719 -            $Qdelete->bindValue(':products_id', $product_id);
   870+            $Qdelete->bindInt(':item_id', $item_id);
720871             $Qdelete->execute();
<>  872+
   873+            $Qdelete = $osC_Database->query('delete from :table_shopping_carts_custom_variants_values where customers_id = :customers_id and shopping_carts_item_id = :shopping_carts_item_id');
   874+            $Qdelete->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   875+            $Qdelete->bindInt(':customers_id', $osC_Customer->getID());
   876+            $Qdelete->bindInt(':shopping_carts_item_id', $item_id);
   877+            $Qdelete->execute();
<_ 721878           }
  722879         }
  723880       }