If Possible I would like to change the related product results to query the category instead of the product name.
Would it be ok to remove the include "require("html/searchresults.php");" and replace it with something like require("html/relatedresults.php");
If so how would I write that query?
Hi,
The related products are selected in products.php by the following code that constructs the appropriate SQL statement, beginning at Line 64 in the distribution:
$where = "";
if (isset($product))
{
if ($product["products"][0]["category"])
{
$where .= "category = '".database_safe($product["products"][0]["category"])."' AND ";
}
}
$where .= "MATCH name AGAINST ('".database_safe($q)."') AND name <> '".database_safe($product["products"][0]["name"])."'";
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".database_safe($q)."') AS relevance FROM `".$config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name ORDER BY relevance LIMIT 3";
To modify this to select products based on category alone you can change this as follows:
$where = "category = '".database_safe($product["products"][0]["category"])."'";
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".database_safe($q)."') AS relevance FROM `".$config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name ORDER BY relevance LIMIT 3";
This would still work with the original html/searchresults.php; however if you want to format the related products differently then simply start with a copy of this file as your new html/relatedproducts.php and modify as required...
Hope this helps,
Cheers,
David.