You are here:  » product of the day

Support Forum



product of the day

Submitted by rolli1 on Tue, 2007-05-15 08:16 in

Hi David,
how can I integrate a single product of the day in my website?

Regards

Roland

Submitted by support on Tue, 2007-05-15 08:42

Hi Roland,

See the following thread which shows how to select featured products that change daily:

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

In your case, simply use "LIMIT 1" on the end instead of "LIMIT 4". You can then use the featured product HTML module to display the product. Here's the complete code to add to index.php:

  unset($featured);
  $seed = intval(date("Ymd"));
  $sql = "SELECT name FROM `".$config_databaseTablePrefix."products` ORDER BY RAND(".$seed.") LIMIT 1";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);
    $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"]);
      }
    }
  }
  if (isset($featured)) require("html/featured.php");

If you want to display the "Product Of The Day" differently, copy html/featured.php as a new file, and then change the code above to include your new version; and make changes to the HTML in the new file.

Cheers,
David.

Submitted by rolli1 on Tue, 2007-05-15 10:31

Thanks this works, but how can I manage to show 5 random featured Products as well as a product of the day?

regards

Roland

Submitted by support on Tue, 2007-05-15 16:39

Hi Roland,

This and the featured products code can work together. If you make the changes described in the other thread to make featured products random, then add the above code you should then have both random featured products and your product of the day.

Hope this helps,
Cheers,
David.

Submitted by rolli1 on Tue, 2007-05-15 20:11

Hi DAvid,

sorry, but I do not understand your instructions. Where have I to include ther code above and what should I do with the copy of the htm/featured.php?

Regards

Roland

Submitted by support on Wed, 2007-05-16 08:34

Hello Roland,

If you want to email me your index.php I will add the two blocks of code for you! Please bear with me however as I am moving house tomorrow but I will get you code back ASAP...

Cheers,
David.

Submitted by marco on Wed, 2008-01-30 09:10

Hi,

This mod works great on my site.
Is there a way in which i can manually exclude some products to become 'product of the day'?

Thanks,
Marco.

Submitted by support on Wed, 2008-01-30 09:13

Hi Marco,

The quickest way is to add a NOT IN list to the SQL; so where you have:

$sql = "SELECT name FROM `".$config_databaseTablePrefix."products` ORDER BY RAND(".$seed.") LIMIT 1";

...change this to:

$sql = "SELECT name FROM `".$config_databaseTablePrefix."products` WHERE name NOT IN ('Product 1','Product 2','Product 3') ORDER BY RAND(".$seed.") LIMIT 1";

That should do the trick!
Cheers,
David.