Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1680
 
1687
 
1687
 
shopping_cart.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shopping_cart.php 1680 2007-08-29 21:02:22Z hpdl $
   3+  $Id: shopping_cart.php 1687 2007-09-03 19:43:04Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
301301     public function add($product_id, $quantity = null) {
  302302       global $osC_Database, $osC_Services, $osC_Language, $osC_Customer;
  303303 
<> 304 -      if ( is_numeric($product_id) ) {
  305 -        $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');
  306 -        $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
  307 -        $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
  308 -        $Qproduct->bindInt(':default_flag', 1);
  309 -        $Qproduct->bindInt(':products_id', $product_id);
  310 -        $Qproduct->execute();
   304+      if ( !is_numeric($product_id) ) {
   305+        return false;
   306+      }
311307 
<> 312 -        if ( $Qproduct->valueInt('products_status') === 1 ) {
  313 -          if ( $this->exists($product_id) ) {
  314 -            $item_id = $this->getBasketID($product_id);
   308+      $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');
   309+      $Qproduct->bindTable(':table_products', TABLE_PRODUCTS);
   310+      $Qproduct->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
   311+      $Qproduct->bindInt(':default_flag', 1);
   312+      $Qproduct->bindInt(':products_id', $product_id);
   313+      $Qproduct->execute();
315314 
<> 316 -            if ( !is_numeric($quantity) ) {
  317 -              $quantity = $this->getQuantity($item_id) + 1;
  318 -            }
   315+      if ( $Qproduct->valueInt('products_status') === 1 ) {
   316+        if ( $this->exists($product_id) ) {
   317+          $item_id = $this->getBasketID($product_id);
319318 
<> 320 -            $this->_contents[$item_id]['quantity'] = $quantity;
   319+          if ( !is_numeric($quantity) ) {
   320+            $quantity = $this->getQuantity($item_id) + 1;
   321+          }
321322 
<> 322 -            if ( $osC_Customer->isLoggedOn() ) {
  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);
  326 -              $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
  327 -              $Qupdate->bindInt(':item_id', $item_id);
  328 -              $Qupdate->execute();
  329 -            }
  330 -          } else {
  331 -            if ( !is_numeric($quantity) ) {
  332 -              $quantity = 1;
  333 -            }
   323+          $this->_contents[$item_id]['quantity'] = $quantity;
334324 
<> 335 -            $Qdescription = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
  336 -            $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
  337 -            $Qdescription->bindInt(':products_id', ($Qproduct->valueInt('parent_id') > 0) ? $Qproduct->valueInt('parent_id') : $product_id);
  338 -            $Qdescription->bindInt(':language_id', $osC_Language->getID());
  339 -            $Qdescription->execute();
   325+          if ( $osC_Customer->isLoggedOn() ) {
   326+            $Qupdate = $osC_Database->query('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
   327+            $Qupdate->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   328+            $Qupdate->bindInt(':quantity', $quantity);
   329+            $Qupdate->bindInt(':customers_id', $osC_Customer->getID());
   330+            $Qupdate->bindInt(':item_id', $item_id);
   331+            $Qupdate->execute();
   332+          }
   333+        } else {
   334+          if ( !is_numeric($quantity) ) {
   335+            $quantity = 1;
   336+          }
340337 
<> 341 -            $price = $Qproduct->value('products_price');
   338+          $Qdescription = $osC_Database->query('select products_name, products_keyword from :table_products_description where products_id = :products_id and language_id = :language_id');
   339+          $Qdescription->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
   340+          $Qdescription->bindInt(':products_id', ($Qproduct->valueInt('parent_id') > 0) ? $Qproduct->valueInt('parent_id') : $product_id);
   341+          $Qdescription->bindInt(':language_id', $osC_Language->getID());
   342+          $Qdescription->execute();
342343 
<> 343 -            if ( $osC_Services->isStarted('specials') ) {
  344 -              global $osC_Specials;
   344+          $price = $Qproduct->value('products_price');
345345 
<> 346 -              if ( $new_price = $osC_Specials->getPrice($product_id) ) {
  347 -                $price = $new_price;
  348 -              }
   346+          if ( $osC_Services->isStarted('specials') ) {
   347+            global $osC_Specials;
   348+
   349+            if ( $new_price = $osC_Specials->getPrice($product_id) ) {
   350+              $price = $new_price;
349351             }
<>  352+          }
350353 
<> 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();
   354+          if ( $osC_Customer->isLoggedOn() ) {
   355+            $Qid = $osC_Database->query('select max(item_id) as item_id from :table_shopping_carts where customers_id = :customers_id');
   356+            $Qid->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   357+            $Qid->bindInt(':customers_id', $osC_Customer->getID());
   358+            $Qid->execute();
356359 
<> 357 -              $item_id = $Qid->valueInt('item_id') + 1;
  358 -            } else {
  359 -              $item_id = max(array_keys($this->_contents)) + 1;
  360 -            }
   360+            $item_id = $Qid->valueInt('item_id') + 1;
   361+          } else {
   362+            $item_id = max(array_keys($this->_contents)) + 1;
   363+          }
361364 
<> 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'));
   365+          $this->_contents[$item_id] = array('item_id' => $item_id,
   366+                                             'id' => $product_id,
   367+                                             'parent_id' => $Qproduct->valueInt('parent_id'),
   368+                                             'name' => $Qdescription->value('products_name'),
   369+                                             'keyword' => $Qdescription->value('products_keyword'),
   370+                                             'image' => $Qproduct->value('image'),
   371+                                             'price' => $price,
   372+                                             'quantity' => $quantity,
   373+                                             'weight' => $Qproduct->value('products_weight'),
   374+                                             'tax_class_id' => $Qproduct->valueInt('products_tax_class_id'),
   375+                                             'date_added' => osC_DateTime::getShort(osC_DateTime::getNow()),
   376+                                             'weight_class_id' => $Qproduct->valueInt('products_weight_class'));
374377 
<> 375 -            if ( $osC_Customer->isLoggedOn() ) {
  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);
  378 -              $Qnew->bindInt(':customers_id', $osC_Customer->getID());
  379 -              $Qnew->bindInt(':item_id', $item_id);
  380 -              $Qnew->bindInt(':products_id', $product_id);
  381 -              $Qnew->bindInt(':quantity', $quantity);
  382 -              $Qnew->bindRaw(':date_added', 'now()');
  383 -              $Qnew->execute();
  384 -            }
   378+          if ( $osC_Customer->isLoggedOn() ) {
   379+            $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)');
   380+            $Qnew->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
   381+            $Qnew->bindInt(':customers_id', $osC_Customer->getID());
   382+            $Qnew->bindInt(':item_id', $item_id);
   383+            $Qnew->bindInt(':products_id', $product_id);
   384+            $Qnew->bindInt(':quantity', $quantity);
   385+            $Qnew->bindRaw(':date_added', 'now()');
   386+            $Qnew->execute();
   387+          }
385388 
<> 386 -            if ( $Qproduct->valueInt('parent_id') > 0 ) {
  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.products_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');
  388 -              $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
  389 -              $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
  390 -              $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
  391 -              $Qvariant->bindInt(':products_id', $product_id);
  392 -              $Qvariant->bindInt(':languages_id', $osC_Language->getID());
  393 -              $Qvariant->bindInt(':languages_id', $osC_Language->getID());
  394 -              $Qvariant->execute();
   389+          if ( $Qproduct->valueInt('parent_id') > 0 ) {
   390+            $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.products_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');
   391+            $Qvariant->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
   392+            $Qvariant->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
   393+            $Qvariant->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
   394+            $Qvariant->bindInt(':products_id', $product_id);
   395+            $Qvariant->bindInt(':languages_id', $osC_Language->getID());
   396+            $Qvariant->bindInt(':languages_id', $osC_Language->getID());
   397+            $Qvariant->execute();
395398 
<> 396 -              while ( $Qvariant->next() ) {
  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'));
   399+            while ( $Qvariant->next() ) {
   400+              $group_title = osC_Variants::getGroupTitle($Qvariant->value('module'), $Qvariant->toArray());
   401+              $value_title = osC_Variants::getValueTitle($Qvariant->value('module'), $Qvariant->toArray());
   402+              $has_custom_value = osC_Variants::hasCustomValue($Qvariant->value('module'));
400403 
<> 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);
   404+              $this->_contents[$item_id]['variants'][] = array('group_id' => $Qvariant->valueInt('group_id'),
   405+                                                               'value_id' => $Qvariant->valueInt('value_id'),
   406+                                                               'group_title' => $group_title,
   407+                                                               'value_title' => $value_title,
   408+                                                               'has_custom_value' => $has_custom_value);
406409 
<> 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 -                }
   410+              if ( $osC_Customer->isLoggedOn() && ($has_custom_value === true) ) {
   411+                $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)');
   412+                $Qnew->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
   413+                $Qnew->bindInt(':shopping_carts_item_id', $item_id);
   414+                $Qnew->bindInt(':customers_id', $osC_Customer->getID());
   415+                $Qnew->bindInt(':products_id', $product_id);
   416+                $Qnew->bindInt(':products_variants_values_id', $Qvariant->valueInt('value_id'));
   417+                $Qnew->bindValue(':products_variants_values_text', $value_title);
   418+                $Qnew->execute();
417419               }
  418420             }
  419421           }
<> 420 -
  421 -          $this->_cleanUp();
  422 -          $this->_calculate();
423422         }
<>  423+
   424+        $this->_cleanUp();
   425+        $this->_calculate();
<_ 424426       }
  425427     }
  426428