You are here:  » average price savings


average price savings

Submitted by philstone on Tue, 2015-11-24 22:53 in

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

Submitted by support on Wed, 2015-11-25 09:26

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

Submitted by philstone on Wed, 2015-11-25 10:56

Perfect David!

Thanks!