Hi David
I'm looking to try something that a large comparison site do, where they show the percentage of savings and actual savings against the average price
eg
merchant 1: £100
merchant 2: £180
merchant 3: £220
merchant 4: £300
total saving would be £200 - cheapest to dearest = 300% saving (This is what I currently use)
Total of price column / num merchants = Average price would be £200, so there would be a £100 saving against the average saving = 100% saving
would this be possible?
Thanks
Phil
Hello Phil,
Sure - at the top of html/product.php, add the following:
<?php
$total = 0;
foreach($prices["products"] as $p)
{
$total += $p["price"];
}
$averagePrice = tapestry_decimalise($total / count($prices["products"]));
$saving = round((($averagePrice - $prices["products"][0]["price"])/$averagePrice)*100,2);
?>
And then within the main HTML body, you can display the saving, conditionally if one exists, using:
<?php if ($saving): ?>
Saving <?php print $saving; ?>% against average price
<?php endif; ?>
Using round() with a the second parameter of 2 will give the saving to 2 decimal places which you can change as required...
Cheers,
David.
--
PriceTapestry.com