Hi,
I've recently downloaded the newest version on PT but just can't see how to display the merchant name under the product name for each search result on the search.php page.
On the old PT, it was
<?php
print $product["name"];
?>
Thanks,
- Quentin
Hi David,
Thanks for your help, that worked fine and yes, I will need the re-query for when there is more than one merchant please.
- Quentin
Hi Quentin,
Sure - in addition to the above modification, in search.php look for the following code at line 391:
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
...and REPLACE with:
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
if ($product["numMerchants"] > 1)
{
$sql = "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($searchresults["products"][$k]["name"])."' ORDER BY price LIMIT 1";
database_querySelect($sql,$rows);
$searchresults["products"][$k]["merchant"] = $rows[0]["merchant"];
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi David,
Thanks for code, slight mistake in your code. I think it must be be "if ($product["numMerchants"] > 1)" on the second line.
Thanks,
- Quentin
oops - not sure where that got to!
Corrected above.
Cheers,
David.
--
PriceTapestry.com
Hi David,
Quick question, on the html/product.php page, after using your mods, if there are 2 merchants with the same product name, it displays information for both merchants. How would you modify the page to only display the information for the merchant that you have click through with?
Thanks,
- Quentin
Hello Quentin,
If i've understood correctly - it would be straight forward to pass through a "merchant" parameter in the product page URL from search results generated from merchant: search results (e.g. going to Merchant A-Z, then clicking on a merchant name).
To try this, in search.php look for the following code at line 391:
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
...and REPLACE with;
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
if ($parts[0]=="merchant")
{
if ($config_useRewrite)
{
$searchresults["products"][$k]["productHREF"] .= "?merchant=".urlencode($searchresults["products"][$k]["merchant"]);
}
else
{
$searchresults["products"][$k]["productHREF"] .= "&merchant=".urlencode($searchresults["products"][$k]["merchant"]);
}
}
Then in products.php, look for the following code at line 12:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."'";
...and REPLACE with:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE normalised_name = '".database_safe($q)."'";
if (isset($_GET["merchant"]))
{
$sql .= " AND merchant='".database_safe($_GET["merchant"])."'";
}
Do consider the possible impact on search engine consideration - it would be possible, for example, to insert a canonical header if a merchant is specified pointing back to the normal product page without the merchant filtering...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Hi David,
I've altered it a little so it works on a normal search as well but is there any way to get it to work on related results on the html/product.php page?
Thanks,
- Quentin
Hi Quentin,
Sure - in products.php look for the following code at line 124:
$sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";
...and REPLACE with:
$sql2 = "SELECT *,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";
Then look for the following code at line 139:
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
...and REPLACE with:
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($searchresults["products"][$k]);
if ($parts[0]=="merchant")
{
if ($config_useRewrite)
{
$searchresults["products"][$k]["productHREF"] .= "?merchant=".urlencode($searchresults["products"][$k]["merchant"]);
}
else
{
$searchresults["products"][$k]["productHREF"] .= "&merchant=".urlencode($searchresults["products"][$k]["merchant"]);
}
}
if ($product["numMerchants"] > 1)
{
$sql = "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($searchresults["products"][$k]["name"])."' ORDER BY price LIMIT 1";
database_querySelect($sql,$rows);
$searchresults["products"][$k]["merchant"] = $rows[0]["merchant"];
}
That should replicate the functionality exactly as modified in search.php for Related Products.
Cheers,
David.
--
PriceTapestry.com
Hi Quentin,
If you edit search.php and look for the following code at line 384:
$sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";
...and REPLACE with:
$sql2 = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";
That will replicate exactly the fields available in html/searchresults.php from earlier versions of Price Tapestry.
Bear in mind (but presumably this is not a problem if working fine with your data set) that if the number of merchants ($product["numMerchants"]) is greater than 1, it cannot be guaranteed that the value of the `merchant` field corresponds to the cheapest price.
This can be resolved easily but does involve a re-query for any result for which there is more than one merchant. If you need to take that into account let me know and I'll describe the changes required.
Cheers,
David.
--
PriceTapestry.com