Hello,
I wanted to add functionality when I search for products.
For example, insert "su merchant" and an icon (heart) where I directly insert the product on the shopping list.
It's possible?
So if there are 2 shops or more, can't you enter the shop that offers the lowest price?
as for the shopping list it works great!
Hi Tobix,
Sure - first add the following PHP section to the top of html/searchresults.php:
<?php
$ins = array();
foreach($searchresults["products"] as $product)
{
$ins[] = "'".database_safe($product["name"])."'";
}
$sql = "SELECT name,merchant FROM `".$config_databaseTablePrefix."products` WHERE name IN (".implode(",",$ins).") ORDER by name,price";
$cheapest = array();
if (database_querySelect($sql,$rows))
{
foreach($rows as $row)
{
if (!isset($cheapest[$row["name"]]))
{
$cheapest[$row["name"]] = $row["merchant"];
}
}
foreach($searchresults["products"] as $k => $product)
{
$searchresults["products"][$k]["merchant"] = $cheapest[$product["name"]];
}
}
?>
And then in the loop, you use how you want e.g.
Best price from <?php print $product["merchant"]; ?>
Cheers,
David.
--
PriceTapestry.com
Hi Tobix,
Sure - first add the following PHP section to the top of html/searchresults.php
<?php
$product_shoppingList = tapestry_shoppingList();
?>
And then within the loop, at the point you want to display the heart use:
<?php
if (!isset($product_shoppingList[$product["name"]]))
{
print "<a href='".tapestry_shoppingListHREF()."?add=".urlencode($product["name"])."'>❤</a>";
}
?>
(for example just before the closing
</div>
at line 67 to show the icon below the Compare Prices / More Information link)Regarding merchant, bear in mind that if prices are compared whilst there is a merchant field in the $product array if numMerchants is greater than 1 it is not defined which product record it is taken from as search results are generated using a summary query however to display if that is not the case you can use as follows;
<?php
if ($product["numMerchants"]==1)
{
print $product["merchant"];
}
?>
Cheers,
David.
--
PriceTapestry.com