Latest News:
v1.2.0 Released Tonight!
on June 21, 2008, 05:12:05 PM [View]
Welcome, Guest. Please login or register.
July 24, 2008, 03:50:29 AM
Show Unread Posts | View Replies to Your Posts


Login with username, password and session length
cpCommerce Support  |  Version 1.x.x  |  Contributions  |  Submissions  |  Topic: Main Display 0 Members and 1 Guest are viewing this topic.
Pages: [1] Send this topic Print
Author Topic: Main Display  (Read 1117 times)
Jenius
Junior Member
*
Offline Offline

Posts: 25


View Profile WWW
« on: May 20, 2007, 09:07:48 AM »

I changed the main display code a bit so that it only displays each section if you have something in that section. (It's not good marketing when your first 2 sections say you have 0 products on sale and 0 this month.)

Here's the code for index.onsale.php (I changed all the other section's code in a same way).


Code:
<?php
  
if (!defined("CPCOMMERCE_LOADED"))
  {
    die(
"You are not allowed to access this script.");
  }
      
// Query the Database for Products On Sale
      
if ($config['pageProducts'] <= 0) {
        
$config['pageProducts'] = 15;
        
$cibfug['showProducts'] = 3;
      }
  if (
$_SESSION['cpLevel'] == 3)
        
$sql['onsale']   = "select distinct(A.name), A.subproducts, IF (MIN(B.stock) <> 0, IF " .
                           
"(MIN(B.stock) < 0, 1000, MIN(B.stock)), IF (MAX(B.stock) <> 0, MAX(B.stock), " .
                           
"IF (A.stock = -1, 1000, A.stock))) as `stock`, A.id_product, A.thumbnail, " .
                           
"IF (MIN(B.price) <> 0, MIN(B.price), A.price) as `original_price`, D.price " .
                           
"from `" $db_chooser->Products() . "` as A left join " .
                           
"`" $db_chooser->SubProducts() . "` as B on (A.id_product=B.id_product) left " .
                           
"join `" $db_chooser->Categories() . "` as C " .
                           
"on (A.id_category=C.id_category) left join `" $db_chooser->Sales() . "` as D " .
                           
"on (A.id_product=D.id_product) where D.start <= NOW() and D.last >= NOW() " .
                           
"GROUP BY A.name limit 0, {$config['pageProducts']}";
      else
        
$sql['onsale']   = "select distinct(A.name), A.subproducts, IF (MIN(B.stock) <> 0, IF " .
                           
"(MIN(B.stock) < 0, 1000, MIN(B.stock)), IF (MAX(B.stock) <> 0, MAX(B.stock), " .
                           
"IF (A.stock = -1, 1000, A.stock))) as `stock`, A.id_product, A.thumbnail, " .
                           
"IF (MIN(B.price) <> 0, MIN(B.price), A.price) as `original_price`, F.price " .
                           
"from `" $db_chooser->Products() . "` as A left join " .
                           
"`" $db_chooser->SubProducts() . "` as B on " .
                           
"(A.id_product=B.id_product) left join `" $db_chooser->LinkedProducts() . "` as " .
                           
"D on (A.id_product=D.id_product) left join `" $db_chooser->Categories() . "` as " .
                           
"C on (A.id_category=C.id_category or D.id_category=C.id_category) left join " .
                           
"`" $db_chooser->Sales() . "` as F on (A.id_product=F.id_product) where F.start " .
                           
"<= NOW() and F.last >= NOW() and C.visible='1' GROUP BY A.name limit 0, " .
                           
"{$config['pageProducts']}";
      
$query['onsale'] = $db_chooser->sql_query($sql['onsale']) or die($db_chooser->sql_error());
      
  if (
$query['onsale'] && $db_chooser->sql_num_rows($query['onsale'])) {
    
$count 1;}
    else return 
0;
?>

     
 <table class="tblContentModule" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="tdContentTitle">
      <?php echo $output['0251']; ?>
    </td>
  </tr>
  <tr>
    <td class="tdContentText">
      <table id="tblOnSale" border="0" cellpadding="0" cellspacing="0">
     
<?php
      
// Check that the Query is valid and it returns information
      
if ($query['onsale'] && $db_chooser->sql_num_rows($query['onsale'])) {
      
        
// Cycle through the Return Information
        
$count 1;
        while (
$info['onsale'] = $db_chooser->sql_fetch_assoc($query['onsale'])) {
          
// Show the Opening Table Row
          
if (($count 1) % $config['showProducts'] == 0)
            echo 
"<tr>";
          
          
// Output the Cell Header
          
echo "<td class=\"tdOnSaleProduct\">";
          
          
// Output the Uplaoded Image
          
if (trim($info['onsale']['thumbnail']) != "" && 
              
file_exists("{$config['productsthumbnail']}{$info['onsale']['thumbnail']}")) {
            
// Get the Width and Height of the Image
            
$dimensions getimagesize("{$config['productsthumbnail']}{$info['onsale']['thumbnail']}");
            
            
// Output
            
echo "<center><a href=\"product.php?id_product={$info['onsale']['id_product']}\"><img " .
                 
"src=\"{$config['productsthumbnail']}{$info['onsale']['thumbnail']}\" " .
                 
"width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" " .
                 
"alt=\"{$info['onsale']['name']}\" /></a></center>";
            
          
// Output the Default Image
          
} else {
            
// Get the Width and Height of the Image
            
$dimensions getimagesize("{$config['productsthumbnail']}blank.gif");
            
            
// Output
            
echo "<center><a href=\"product.php?id_product={$info['onsale']['id_product']}\"><img " .
                 
"src=\"{$config['productsthumbnail']}blank.gif\" width=\"{$dimensions[0]}\" " .
                 
"height=\"{$dimensions[1]}\" border=\"0\" alt=\"{$info['onsale']['name']}\" " .
                 
"/></a></center>";
          }
          
          
// Output the Name of the Product
          
echo "<center><a href=\"product.php?id_product={$info['onsale']['id_product']}\">" .
               
"{$info['onsale']['name']}</a></center>";
          
          
// Query the Database to see if the SubProducts are all out of Stock
          
$sql['subproducts']   = "select count(*) as `instock` from `" $db_chooser->SubProducts() . "` " .
                                  
"where `id_product`={$info['onsale']['id_product']} and `stock`!=0";
          
$query['subproducts'] = $db_chooser->sql_query($sql['subproducts']);
          
          
// Grab the Results
          
$info['subproducts'] = $db_chooser->sql_fetch_assoc($query['subproducts']);
          
          
// Output the Stock Status
          
if ($info['onsale']['stock'] != 0)
            echo 
"<center><span class=\"spnOnSaleProductInStock\">{$output['0092']}</span> &nbsp; ";
          else
            echo 
"<center><span class=\"spnOnSaleProductOutOfStock\">{$output['0093']}</span> &nbsp; ";
          
          
// Output the Price
          
echo "<span class=\"spnOnSaleProductOnSale\">" format_currency($info['onsale']['price']) .
               
"</span></center></td>";
          
          
// Show the Closing Table Row
          
if ($count $config['showProducts'] == 0)
            echo 
"</tr>";
          
$count++;
        }
        
        
// Close the Table Row Properly
        
if (($count 1) % $config['showProducts'] != 0)
          echo 
"<td colspan=\"" . ($count - (($count 1) % $config['showProducts'])) . "\"></td></tr>";
      }
?>

      </table>
    </td>
  </tr>
</table>
« Last Edit: February 22, 2008, 09:05:36 PM by Jenius » Report to moderator   Logged
Pages: [1] Send this topic Print 
cpCommerce Support  |  Version 1.x.x  |  Contributions  |  Submissions  |  Topic: Main Display
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Horizontal menu with categories melboro 0 243 November 02, 2007, 03:41:00 PM
by melboro
Random products module melboro 1 135 June 15, 2008, 02:11:45 PM
by cpradio

Powered by MySQL Powered by PHP cpCommerce Support | Powered by SMF 1.1.
© 2004, Simple Machines LLC. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!