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
Thanks David,
It well on the features page. What variable changes are needed for it to work on the product.php page?
Thanks
Rod
Hi Rod,
Within the main body of html/product.php, use $mainProduct in place of $product.
Cheers,
David.
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> <?php print translate("from"); ?>
</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>
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.
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.