You are here:  » Price Range Savings

Support Forum



Price Range Savings

Submitted by FirstByte on Thu, 2009-05-28 17:09 in

Hi David,

I'm trying to calculate the amount of money saved between price ranges.
I figured it would be simply enough to get the min and max price values, though when i tried to subtract the min price from the max i keep getting "0" value.

below is what i was playing around with, im a newbie with php.

<?php
$miniPrice=$config_currencyHTML.$product["minPrice"];
$maxiPrice=$config_currencyHTML.$product["maxPrice"];
?>
<?php print $maxiPrice;?> - <?php print $miniPrice;?> = <?php echo $maxiPrice $miniPrice?>

any idea how i can fix it?

cheers
Rod

Submitted by support on Fri, 2009-05-29 08:57

Hi Rod,

Try something like this:

<?php
$miniPrice
=$config_currencyHTML.$product["minPrice"];
$maxiPrice=$config_currencyHTML.$product["maxPrice"];
$saving $product["maxPrice"] - $product["minPrice"];
print 
"The saving is: ".$config_currencyHTML.$saving;
?>

Cheers,
David.

Submitted by FirstByte on Fri, 2009-05-29 12:48

Thanks David,

It well on the features page. What variable changes are needed for it to work on the product.php page?

Thanks
Rod

Submitted by support on Fri, 2009-05-29 12:49

Hi Rod,

Within the main body of html/product.php, use $mainProduct in place of $product.

Cheers,
David.

Submitted by FirstByte on Sat, 2009-05-30 11:28

Hi David,

I changed the variables but can't seem to get it to work, the value is still "0" when i added it to the product.php page.
below is the code i'm currently using.

<span style="color:#000000;">
              <?php if (count($product["products"]) > 1): ?>
                <strong style="font-size:12pt;"><?php print translate("Best Price"); ?></strong>
              <?php else: ?>
                <strong style="font-size:12pt;"><?php print translate("Buy now for "); ?></strong>
              <?php endif; ?>
              <strong style="font-size:12pt;"><?php print $config_currencyHTML.$mainProduct["price"]; ?></strong>&nbsp;<?php print translate("from"); ?>&nbsp;
</span>
<br/>
<span style="color:black;"><?php
$miniPrice=$config_currencyHTML.$mainProduct["minPrice"];
$maxiPrice=$config_currencyHTML.$mainProduct["maxPrice"];
$saving = $mainProduct["maxPrice"] - $mainProduct["minPrice"];
print "The saving is: ".$config_currencyHTML.$saving;
?></span>

Submitted by support on Sat, 2009-05-30 12:19

Hello Rod,

Ah - in this case the calculation would need to be made against the first and last products in the $product["products"] array rather than using minPrice and maxPrice. Try something like this:

<span style="color:black;">
<?php
$numProducts = count($product["products"]);
if ($numProducts > 1)
{
  $minPrice = $product["products"][0]["price"];
  $maxPrice = $product["products"][($numProducts-1)]["price"];
  if ($maxPrice > $minPrice)
  {
    $saving = sprintf("%.2f",($maxPrice - $minPrice));
    print "The saving is: ".$config_currencyHTML.$saving;
  }
}
?>
</span>

Cheers,
David.

Submitted by FirstByte on Mon, 2009-06-01 02:48

Thanks David,
That worked perfectly.