You are here:  » Showing Featured products


Showing Featured products

Submitted by Julian on Tue, 2006-08-08 17:18 in

Is there a way to show different featured products by hand?(not using the built in script)

I am adding extra pages but want different featured products shown on the main page of each section - is there a way to do this ?

Thanks

Submitted by support on Tue, 2006-08-08 17:30

Sure - what you'd need to do is copy the code used to select and display the featured products from index.php and then modify the SQL to select the products manually rather than using the built in feature products list.

For example, the following code will display the products "Foo" and "Bar" using the built in feature products display module. You could either use it like this directly, or copy and modify your own HTML module to do the display. Here's the code (note that this must be on a page that has the Price Tapestry standard headers included):

<?php
  $sqlIn 
"'Foo','Bar'";
  
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
  
database_querySelect($sql,$rows);
  
$featured["products"] = $rows;
  foreach(
$featured["products"] as $k => $product)
  {
    if (
$config_useRewrite)
    {
      
$featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
      
$featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
    }
    else
    {
      
$featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
      
$featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
    }
  }
  require(
"html/featured.php");
?>

Hope this helps!
David.

Submitted by Julian on Tue, 2006-08-08 17:46

thanks - works a treat :-)

Submitted by Julian on Tue, 2006-08-08 18:18

just another thought - is it possible to pull/update the featured products 'foo' & 'bar' from a .txt file for easy updating ?

also on the product page is it possible to change the link to the suppliers website into a buy button/graphic ?

thank

Submitted by Peter on Tue, 2006-08-08 20:57

Hello,

the button can you made by following:

Change row 15 from html/prices.php to...

<td align='center'><a href='<?php print tapestry_buyURL($product); ?>' <?php print javascript_statusBar("go to ".$product["merchant"]); ?> target='_blank'><img src="http://www.yourdomain.com/images/yourgraphic.gif" border="0"></a></td>

Cheers, Peter

Submitted by support on Wed, 2006-08-09 09:46

Thanks for that, Peter.

Might be worth having a look at the following thread which shows how to upload and use merchant logos by creating filenames that have the same name as the merchant in your database....

http://www.pricetapestry.com/node/314

Ok, here's a stab at a modified version of the code above using a text file to store a set of featured merchants - i've not tested this but it should work.....! :)

<?php
  $featuredProducts 
= array();
  
$featuredFilename "featured.txt";
  
$file fopen($featuredFilename,"r");
  while(!
feof($file))
  {
    
// get a line from the file, and remove any white space
    
$line trim(fgets($file));
    
// if we're left with some text, add it to the array in single-quotes (ready for the SQL)
    
if ($line$featuredProducts[] = "'".$line."'";
  }
  
fclose($file);
  
$sqlIn implode(",",$featuredProducts);
  
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
  
database_querySelect($sql,$rows);
  
$featured["products"] = $rows;
  foreach(
$featured["products"] as $k => $product)
  {
    if (
$config_useRewrite)
    {
      
$featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
      
$featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
    }
    else
    {
      
$featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
      
$featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
    }
  }
  require(
"html/featured.php");
?>

The file (featured.txt in this example) simply contains product names one per line. To use the code on different pages, simply use a different text file, and change the filename in the code.

Hope this helps!
David.

Submitted by Julian on Wed, 2006-08-09 11:04

Thanks guys

all working now :-)