You are here:  » Random Products from the same store

Support Forum



Random Products from the same store

Submitted by bloach on Tue, 2008-06-10 13:42 in

Hi David,

I am using the default template and want to add 3 random products on the product page under the Related products in the same fashion.

What code should I use?

Thanks

Submitted by support on Tue, 2008-06-10 14:00

Hi,

This is quite easy to do - but you mention that you want them from the same store. Would this be the same store (merchant) as the main featured product on the page? If, so the following code is all you need to do this. Look near the end of products.php for the following line:

if (isset($related)) require("html/related.php");

To use the related.php HTML module again for your random products, add the following code on the next line:

    unset($related);
    unset($searchresults);
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE merchant='".$mainProduct["merchant"]."' ORDER BY RAND() GROUP BY name LIMIT 3";
    $searchresults["numRows"] = database_querySelect($sql,$rows);
    $searchresults["products"] = $rows;
    if ($searchresults["numRows"])
    {
      foreach($searchresults["products"] as $k => $related)
      {
        if ($config_useRewrite)
        {
          $searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($related["name"]).".html";
          if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../".$searchresults["products"][$k]["productHREF"];
        }
        else
        {
          $searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($related["name"]);
        }
      }
      $related = true;
    }
    if (isset($related)) require("html/related.php");

Cheers,
David.

Submitted by bloach on Fri, 2008-06-13 09:51

Thanks David,

For some reason, it won't work.

http://comparison.topbargains.com.au

Submitted by support on Fri, 2008-06-13 09:53

Hi,

Easiest thing to do is if you could email me your modified products.php (reply to your reg code or forum registration email) and i'll take a look for you...

Cheers,
David.

Submitted by bloach on Sun, 2008-06-15 02:55

Thanks David,

Here is the code:

{code saved}

_____________________________________________________
My Australian Shopping Comparison Site

Australian Shopping Comparison

Submitted by support on Sun, 2008-06-15 08:10

Hi,

I have emailed you a modified version of product.php with the random products code included...

Cheers,
David.

Submitted by FirstByte on Fri, 2008-07-25 15:27

Hi David,

any chance in getting the copy of the random product code as well?

regards
Rod

Submitted by support on Sat, 2008-07-26 09:36

Hi Rod,

Sent as requested...

Cheers,
David.