You are here:  » Top 5 best reviewed products + additional data

Support Forum



Top 5 best reviewed products + additional data

Submitted by redspark on Tue, 2010-08-31 11:32 in

Hi David,

I'm looking for a way to add the top 5 best reviewed products on top of my category and on top of that, I want to add some extra information to those products (to have a better compare). I'm thinking of adding extra tables in the product database, but i cant add the info via the productfeed. I need a seperate form to add the information.

I have searched the forum if somebody else had the same idea before but i couldnt find anything. Have you ever had that request before i could reuse?

regards,

B.

Submitted by support on Tue, 2010-08-31 13:17

Hi B.,

Sure - you can use the Featured Products HTML module to display the top n rated products as follows;

  $sql = "SELECT *,1 AS sequence FROM `".$config_databaseTablePrefix."products` ORDER BY rating DESC LIMIT 3";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    $sqlCase = "CASE normalised_name";
    foreach($rows as $featured)
    {
      $featured["name"] = tapestry_normalise($featured["name"]);
      $sqlNames[] = "'".$featured["name"]."'";
      $sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
    }
    $sqlCase .= " END AS sequence";
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
    database_querySelect($sql,$rows);
    $featured["products"] = $rows;
    foreach($featured["products"] as $k => $product)
    {
      $featured["products"][$k]["productHREF"] = $config_baseHREF.tapestry_hyphenate($product["normalised_name"]).".html";
    }
  }
  if (isset($featured)) require("html/featured.php");

To display above the category list, simply insert the above into categories.php immediately before the following code at around line 41:

  require("html/atoz.php");

A popular way to display additional custom content per product is via simple text file mechanism which doesn't require any database modification - one method is described in the following thread

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

In the above case, I would then recommend creating a new HTML module in place of html/featured.php from which you can pull in the above /custom/ content. To do this, make a copy of html/featured.php, and call it html/toprated.php. In the code above, replace

  require("html/featured.php");

...with:

  require("html/toprated.php");

Finally, in html/toprated.php, you can then pull in your custom content within the loop - look for the following code at the end of the loop;

      <?php endforeach; ?>

...and REPLACE with:

      $filename = "custom/".$product["name"].".html";
      if (file_exists($filename))
      {
        require($filename);
      }
      <?php endforeach; ?>

Cheers,
David.
--
PriceTapestry.com