[TEP-COMMIT] CVS: catalog/catalog/includes/modules also_purchased_products.php,1.22,1.23 new_products.php,1.37,1.38 upcoming_products.php,1.26,1.27

cvs-OfajU3CKLf1/[email protected] Mon, 16 Feb 2004 08:35:49 +0100
Newsgroups gmane.comp.web.oscommerce.cvs
Message-ID <[email protected]>
Update of /pack/cvsroots/oscommerce/catalog/catalog/includes/modules
In directory sunsite.dk:/tmp/cvs-serv539/modules

Modified Files:
	also_purchased_products.php new_products.php 
	upcoming_products.php 
Log Message:
use the new database class


Index: also_purchased_products.php
===================================================================
RCS file: /pack/cvsroots/oscommerce/catalog/catalog/includes/modules/also_purchased_products.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- also_purchased_products.php	2003/11/17 20:10:55	1.22
+++ also_purchased_products.php	2004/02/16 07:29:50	1.23
@@ -5,14 +5,18 @@
   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
 
-  Copyright (c) 2003 osCommerce
+  Copyright (c) 2004 osCommerce
 
   Released under the GNU General Public License
 */
 
   if (isset($_GET['products_id'])) {
-    $orders_query = tep_db_query("select p.products_id, p.products_image from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p where opa.products_id = '" . (int)$_GET['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$_GET['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
-    $num_products_ordered = tep_db_num_rows($orders_query);
+    $Qorders = $osC_Database->query("select p.products_id, p.products_image from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p where opa.products_id = '" . (int)$_GET['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$_GET['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
+    $Qorders->setCache('also_purchased-' . (int)$_GET['products_id'], 120);
+    $Qorders->execute();
+
+    $num_products_ordered = $Qorders->numberOfRows();
+
     if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {
 ?>
 <!-- also_purchased_products //-->
@@ -25,11 +29,12 @@
       $row = 0;
       $col = 0;
       $info_box_contents = array();
-      while ($orders = tep_db_fetch_array($orders_query)) {
-        $orders['products_name'] = tep_get_products_name($orders['products_id']);
+      while ($Qorders->next()) {
+        $products_name = tep_get_products_name($Qorders->valueInt('products_id'));
+
         $info_box_contents[$row][$col] = array('align' => 'center',
                                                'params' => 'class="smallText" width="33%" valign="top"',
-                                               'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name'] . '</a>');
+                                               'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $Qorders->valueInt('products_id')) . '">' . tep_image(DIR_WS_IMAGES . $Qorders->value('products_image'), $Qorders->value('products_name'), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $Qorders->valueInt('products_id')) . '">' . $products_name . '</a>');
 
         $col ++;
         if ($col > 2) {
@@ -37,6 +42,8 @@
           $row ++;
         }
       }
+
+      $Qorders->freeResult();
 
       new contentBox($info_box_contents);
 ?>

Index: new_products.php
===================================================================
RCS file: /pack/cvsroots/oscommerce/catalog/catalog/includes/modules/new_products.php,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- new_products.php	2003/12/18 23:52:15	1.37
+++ new_products.php	2004/02/16 07:29:50	1.38
@@ -5,21 +5,36 @@
   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
 
-  Copyright (c) 2003 osCommerce
+  Copyright (c) 2004 osCommerce
 
   Released under the GNU General Public License
 */
-?>
-<!-- new_products //-->
-<?php
 
-  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
-    $new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
+  if ($current_category_id == '0') {
+    $Qnewproducts = $osC_Database->query('select p.products_id, p.products_image, p.products_tax_class_id, p.products_price, pd.products_name from :table_products p, :table_products_description pd where p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id order by p.products_date_added desc limit :max_display_new_products');
+    $Qnewproducts->bindRaw(':table_products', TABLE_PRODUCTS);
+    $Qnewproducts->bindRaw(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
+    $Qnewproducts->bindInt(':language_id', $osC_Session->value('languages_id'));
+    $Qnewproducts->bindInt(':max_display_new_products', MAX_DISPLAY_NEW_PRODUCTS);
   } else {
-    $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
+    $Qnewproducts = $osC_Database->query('select distinct p.products_id, p.products_image, p.products_tax_class_id, p.products_price, pd.products_name from :table_products p, :table_products_description pd, :table_products_to_categories p2c, :table_categories c where c.parent_id = :parent_id and c.categories_id = p2c.categories_id and p2c.products_id = p.products_id and p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = :language_id order by p.products_date_added desc limit :max_display_new_products');
+    $Qnewproducts->bindRaw(':table_products', TABLE_PRODUCTS);
+    $Qnewproducts->bindRaw(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
+    $Qnewproducts->bindRaw(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
+    $Qnewproducts->bindRaw(':table_categories', TABLE_CATEGORIES);
+    $Qnewproducts->bindInt(':parent_id', $current_category_id);
+    $Qnewproducts->bindInt(':language_id', $osC_Session->value('languages_id'));
+    $Qnewproducts->bindInt(':max_display_new_products', MAX_DISPLAY_NEW_PRODUCTS);
   }
 
-  if (tep_db_num_rows($new_products_query) > 0) {
+  $Qnewproducts->setCache('new_products-' . $osC_Session->value('language') . '-' . $current_category_id, '720');
+
+  $Qnewproducts->execute();
+
+  if ($Qnewproducts->numberOfRows()) {
+?>
+<!-- new_products //-->
+<?php
     $info_box_contents = array();
     $info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
 
@@ -29,11 +44,19 @@
     $col = 0;
 
     $info_box_contents = array();
-    while ($new_products = tep_db_fetch_array($new_products_query)) {
-      $new_products['products_name'] = tep_get_products_name($new_products['products_id']);
+
+    while ($Qnewproducts->next()) {
+      $specials_price = tep_get_products_special_price($Qnewproducts->valueInt('products_id'));
+
+      $products_price = $osC_Currencies->displayPrice($Qnewproducts->valueDecimal('products_price'), $Qnewproducts->valueInt('products_tax_class_id'));
+
+      if (tep_not_null($specials_price)) {
+        $products_price = '<s>' . $products_price . '</s>&nbsp;<span class="productSpecialPrice">' . $osC_Currencies->displayPrice($specials_price, $Qnewproducts->valueInt('products_tax_class_id')) . '</span>';
+      }
+
       $info_box_contents[$row][$col] = array('align' => 'center',
                                              'params' => 'class="smallText" width="33%" valign="top"',
-                                             'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $osC_Currencies->displayPrice($new_products['products_price'], $new_products['products_tax_class_id']));
+                                             'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $Qnewproducts->valueInt('products_id')) . '">' . tep_image(DIR_WS_IMAGES . $Qnewproducts->value('products_image'), $Qnewproducts->value('products_name'), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $Qnewproducts->valueInt('products_id')) . '">' . $Qnewproducts->value('products_name') . '</a><br>' . $products_price);
 
       $col ++;
 
@@ -44,6 +67,10 @@
     }
 
     new contentBox($info_box_contents);
-  }
+
+    $Qnewproducts->freeResult();
 ?>
 <!-- new_products_eof //-->
+<?php
+  }
+?>

Index: upcoming_products.php
===================================================================
RCS file: /pack/cvsroots/oscommerce/catalog/catalog/includes/modules/upcoming_products.php,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- upcoming_products.php	2003/11/17 20:22:59	1.26
+++ upcoming_products.php	2004/02/16 07:29:50	1.27
@@ -5,13 +5,21 @@
   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
 
-  Copyright (c) 2003 osCommerce
+  Copyright (c) 2004 osCommerce
 
   Released under the GNU General Public License
 */
 
-  $expected_query = tep_db_query("select p.products_id, pd.products_name, products_date_available as date_expected from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where to_days(products_date_available) >= to_days(now()) and p.products_id = pd.products_id and pd.language_id = '" . (int)$osC_Session->value('languages_id') . "' order by " . EXPECTED_PRODUCTS_FIELD . " " . EXPECTED_PRODUCTS_SORT . " limit " . MAX_DISPLAY_UPCOMING_PRODUCTS);
-  if (tep_db_num_rows($expected_query) > 0) {
+  $Qupcoming = $osC_Database->query('select p.products_id, pd.products_name, p.products_date_available as date_expected from :table_products p, :table_products_description pd where to_days(p.products_date_available) >= to_days(now()) and p.products_id = pd.products_id and pd.language_id = :language_id order by :expected_products_field :expected_products_sort limit :max_display_upcoming_products');
+  $Qupcoming->bindRaw(':table_products', TABLE_PRODUCTS);
+  $Qupcoming->bindRaw(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
+  $Qupcoming->bindInt(':language_id', $osC_Session->value('languages_id'));
+  $Qupcoming->bindRaw(':expected_products_field', EXPECTED_PRODUCTS_FIELD);
+  $Qupcoming->bindRaw(':expected_products_sort', EXPECTED_PRODUCTS_SORT);
+  $Qupcoming->bindInt(':max_display_upcoming_products', MAX_DISPLAY_UPCOMING_PRODUCTS);
+  $Qupcoming->execute();
+
+  if ($Qupcoming->numberOfRows() > 0) {
 ?>
 <!-- upcoming_products //-->
           <tr>
@@ -25,7 +33,7 @@
               </tr>
 <?php
     $row = 0;
-    while ($expected = tep_db_fetch_array($expected_query)) {
+    while ($Qupcoming->next()) {
       $row++;
       if (($row / 2) == floor($row / 2)) {
         echo '              <tr class="upcomingProducts-even">' . "\n";
@@ -33,8 +41,8 @@
         echo '              <tr class="upcomingProducts-odd">' . "\n";
       }
 
-      echo '                <td class="smallText">&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $expected['products_id']) . '">' . $expected['products_name'] . '</a>&nbsp;</td>' . "\n" .
-           '                <td align="right" class="smallText">&nbsp;' . tep_date_short($expected['date_expected']) . '&nbsp;</td>' . "\n" .
+      echo '                <td class="smallText">&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $Qupcoming->valueInt('products_id')) . '">' . $Qupcoming->value('products_name') . '</a>&nbsp;</td>' . "\n" .
+           '                <td align="right" class="smallText">&nbsp;' . tep_date_short($Qupcoming->value('date_expected')) . '&nbsp;</td>' . "\n" .
            '              </tr>' . "\n";
     }
 ?>
@@ -45,5 +53,7 @@
           </tr>
 <!-- upcoming_products_eof //-->
 <?php
+
+    $Qupcoming->freeResult();
   }
 ?>



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click