Submitted by wilkins on Sun, 2008-11-16 23:26 in Price Tapestry
Hi David
I have a large site and would like to create pages for indivdual merchants that shows the specific categories and brands they have in a list (may be A-Z),could this be done?
Reasonably straight forward - you could start with a small modification to the categories.php and brands.php scripts to take an optional merchant=xxx parameter in order to filter the list. To do this, in categories.php, look for the following code on line 6:
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
...and REPLACE this with:
if ($_GET["merchant"])
{
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($_GET["merchant"])."' ORDER BY category";
}
else
{
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
}
Similarly, in brands.php, look for the following code also on line 6:
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
...and REPLACE this with:
if ($_GET["merchant"])
{
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($_GET["merchant"])."' ORDER BY brand";
}
else
{
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
}
Hi Brent,
Reasonably straight forward - you could start with a small modification to the categories.php and brands.php scripts to take an optional merchant=xxx parameter in order to filter the list. To do this, in categories.php, look for the following code on line 6:
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
...and REPLACE this with:
if ($_GET["merchant"])
{
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($_GET["merchant"])."' ORDER BY category";
}
else
{
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
}
Similarly, in brands.php, look for the following code also on line 6:
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
...and REPLACE this with:
if ($_GET["merchant"])
{
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($_GET["merchant"])."' ORDER BY brand";
}
else
{
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
}
With this in place, you can now link as follows:
http://www.example.com/brands.php?merchant=Example+Merchant
(remember to use + in place of SPACE in merchant names that have spaces)
A quick way to create a navigable index of brand and category pages for all merchants is as follows (ignore PHP tags if already in a PHP section):
<?php
$sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` ORDER BY merchant";
if (database_querySelect($sql,$rows))
{
print "<ul>";
foreach($rows as $feed)
{
$categoryHREF = $config_baseHREF."categories.php?merchant=".urlencode($feed["merchant"]);
$brandHREF = $config_baseHREF."brands.php?merchant=".urlencode($feed["merchant"]);
print "<li>".$feed["merchant"]." - <a href='".$categoryHREF."'>Categories</a> - <a href='".$brandHREF."'>Brands</a></li>";
}
print "</ul>";
}
?>
Cheers,
David.