Hi David,
How would I go about adding the lowest price for a product to the page title, so that it displays something like ProductName from £xxx.xx. I'm already setting the page title by using
$header["title"] =
in products.php
but can't work out how I can get access to the lowest price at this point in the code.
Many thanks
Chris
Hi David,
Is there a way of including the lowest price on other pages, I wanted to include it in the Title attribute of an img tag.
Thanks,
Patrick
Hi Patrick,
In most cases, wherever $product["image_url"] is in context (on a non-product page); the lowest price will be in $product["minPrice"], so you could use something like:
<img src='<?php print $product["image_url"]; ?>' alt='<?php print html_entities($product["name"] . " available from ".$product["minPrice"],ENT_QUOTES,$config_charset); ?>' />
Cheers,
David.
Am I right in thinking that if I were to name a specific product in the alt tag it would bring up the lowest price associated to that product name?
Hi Adrian,
The product would already need to be in "context", i.e. already SELECTed from the database and being used to display information about that product.
A loop that you will come across throughout the script; especially within the /html/ files is something like:
foreach($something["products"] as $product)
{
// do something with each $product here..
}
...and it's within loops like that where you would be able to use $product["minPrice"] to display the minimum price of the product (the name of which is in $product["name"]).
If you wanted to select a specific product, you would need to recreate the search query used by Price Tapestry for that specified product, and then generate your image. For example:
<?php
$productName = "Product Name Here";
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($productName)."' GROUP BY name";
database_querySelect($sql,$products);
$product = $products[0];
print "<img src='".$product["image_url"]."' alt='".html_entities($product["name"],ENT_QUOTES,$config_charset)." available from ".$product["minPrice"]."' />";
?>
Hope this helps!
Cheers,
David.
Hi Chris,
At the position of that code in products.php the minimum price will be in the variable
$product["products"][0]["price"]
...so you could use the following:
$header["title"] = htmlentities($q,ENT_QUOTES,$config_charset)." from £".$product["products"][0]["price"];
Cheers,
David.