Hi David,
I have about 15 merchants for the same product to compare prices.
The image that gets displayed is the image of the cheapest merchant.
My Problem is that some merchants have a slow server connection,
or just really bad quality images.
Thats the reason I want to choose one prefered merchant and two alternative merchants
(if the prefered merchant doesn't sell the product) to pull the image from,
and not from the cheapest merchant.
(Only if the prefered and alternative merchants dont sell the product).
Is there a way to do this?
Big thanks in advance David!
Cheers,
Tony
I'm sorry.. I should have told you before that I'm using the PTO plugin.
What do I have to replace there?
Thank you David!
Tony
Hi Tony,
No problem - to do the equivalent modification in the plugin, look for the following code at line 286 of pto_product.php:
$html_product = $pto_html_product;
...and REPLACE with:
$imageMerchants = array("Merchant 1","Merchant 2","Merchant 3");
$done = FALSE;
foreach($imageMerchants as $imageMerchant)
{
for($i=0;$i<$numRows;$i++)
{
$v = $wpdb->last_result[$i];
if (($v->merchant==$imageMerchant) && ($v->image_url))
{
$product->image_url = $v->image_url;
$done = TRUE;
break;
}
}
if ($done) break;
}
$html_product = $pto_html_product;
Cheers,
David.
--
PriceTapestry.com
Hi David,
I was wondering if it would be possible to apply this to the search results pages as well? I tried to edit the code but couldn't get it to work, would you be able to give me a few pointers please?
Thanks
gavin
Hello Gavin and welcome to the forum!
It's a little trickier for search results since the result set comes from a summary query so there is only a single image_url value present in each result. This means a re-query would be required, but it can be done in a single query by compiling an appropriate WHERE clause to select product names and image URLs from all merchants ordered by a merchant priority (sequence in the $imageMerchants array). Have a go with the following code inserted at the top of html/searchresults.php:
<?php
$imageMerchants = array("Merchant 1","Merchant 2","Merchant 3");
$merchantIns = array();
$sqlCase = "CASE merchant";
foreach($imageMerchants as $k => $imageMerchant)
{
$merchantIns[] = "'".database_safe($imageMerchant)."'";
$sqlCase .= " WHEN '".database_safe($imageMerchant)."' THEN ".$k;
}
$sqlCase .= " END AS priority";
$productIns = array();
foreach($searchresults["products"] as $product)
{
$productIns[] = "'".database_safe($product["name"])."'";
}
$merchantIn = implode(",",$merchantIns);
$productIn = implode(",",$productIns);
$sql = "SELECT name,image_url,".$sqlCase."
FROM `".$config_databaseTablePrefix."products`
WHERE merchant IN (".$merchantIn.") AND name IN (".$productIn.")
AND image_url <> '' ORDER BY priority";
database_querySelect($sql,$rows);
$imageOverrides = array();
foreach($rows as $row)
{
if (!isset($imageOverrides[$row["name"]]))
{
$imageOverrides[$row["name"]] = $row["image_url"];
}
}
foreach($searchresults["products"] as $k => $product)
{
if (isset($imageOverrides[$product["name"]]))
$searchresults["products"][$k]["image_url"] = $imageOverrides[$product["name"]];
}
?>
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
I've update this code for the latest version.
$product_main = $product["products"][0];
$imageMerchants = array("Merchant1");
$done = FALSE;
foreach($imageMerchants as $imageMerchant)
{
foreach($product["products"] as $v)
{
if (($v["merchant"]==$imageMerchant) && ($v["image_url"]))
{
$product_main["image_url"] = $v["image_url"];
$done = TRUE;
break;
}
}
if ($done) break;
}
If you want to prioritise name you can use the code below.
$done = FALSE;
foreach($nameMerchants as $nameMerchant)
{
foreach($product["products"] as $v)
{
if (($v["merchant"]==$nameMerchant) && ($v["name"]))
{
$product_main["name"] = $v["name"];
$done = TRUE;
break;
}
}
if ($done) break;
}
Hi Tony,
Sure - have a go as follows. In html/product.php look for the following code at line 2:
<?php $mainProduct = $product["products"][0]; ?>
...and REPLACE with:
<?php $mainProduct = $product["products"][0]; ?>
<?php
$imageMerchants = array("Merchant 1","Merchant 2","Merchant 3");
$done = FALSE;
foreach($imageMerchants as $imageMerchant)
{
foreach($product["products"] as $v)
{
if (($v["merchant"]==$imageMerchant) && ($v["image_url"]))
{
$mainProduct["image_url"] = $v["image_url"];
$done = TRUE;
break;
}
}
if ($done) break;
}
?>
Simply replace Merchant 1, Merchant 2 etc. with your preferred image merchants in order of priority...
Cheers,
David.
--
PriceTapestry.com