Hi,
Hopefully the title makes sense, but basically, in some of my feeds some merchants have no description, or a short meaningless one of 20 characters or so, where as some merchants have much better descriptions. I would prefer to use the description of the merchant with the lowest price (on the products page, the search results don't matter as much), but don't want to if they have no description.
I was wondering if it would be possible to have some kind of operator that says something along the lines of
If description is less than 20 chars, use description from another merchant.
Thanks in advance.
Kind Regards,
Craig.
Hi David,
Thank you very much, that has worked like a dream. What would happen if for some reason all merchants had less than 20 character descriptions? I haven't come across this yet and doubt it has happened.
Also, does it ust randomly choose one of the other merchants desription, or is there some logic behind it? Not that it really matters, I'm just curious!
Kind Regards,
Craig.
Hi Craig,
The first version will only overwrite the main description if it is less than 20 characters and another (the first encountered in price ascending order) has a longer description, otherwise it will be left unchanged.
With the second version; the longest description outright is selected; unless there are 2 with the same length, in which case the first one will "win".
Neither version will ever leave you without a description when there would already be one...
Cheers,
David.
Hi Craig,
Sure - this is straight forward to achieve. In html/product.php look for the following code near the top at line 2:
<?php $mainProduct = $product["products"][0]; ?>
...and REPLACE this with:
<?php $mainProduct = $product["products"][0]; ?>
<?php
if (strlen($mainProduct["description"]) <= 20)
{
foreach($product["products"] as $p)
{
if (strlen($p["description"]) > 20)
{
$mainProduct["description"] = $p["description"];
break;
}
}
}
?>
Or alternatively, to find and use the longest description:
<?php $mainProduct = $product["products"][0]; ?>
<?php
foreach($product["products"] as $p)
{
if (strlen($p["description"]) > strlen($mainProduct["description"]))
{
$mainProduct["description"] = $p["description"];
}
}
?>
Cheers,
David.