Have a nice day everyone, I have something to ask your hel, to better understand here is my code:
{math equation=((($order_total-$commission)+$discount+$delivery_charge)*$rate)}
I want that to be pass to another variable,in php I want to be like this
<?php
$var=0
foreach($result as $resultA){
$var = $var+((($order_total-$commission)+$discount+$delivery_charge)*$rate);
}
?>
Hope you can help me guys!
If you're using Smarty 3 I highly recommend ditching the {math}:
{$order_total = 123}
{$commission = 13}
{$discount = 10}
{$delivery_charge = 20}
{$rate = 1.1}
{$result = 0}
{$result = $result + ($order_total - $commission + $discount + $delivery_charge) * $rate}
{$result}
It is both better readable and faster (as the expression is actually compiled, rather than eval()ed
over and over again).
Smarty 2 equivalent:
{assign var="order_total" value=123}
{assign var="commission" value=13}
{assign var="discount" value=10}
{assign var="delivery_charge" value=20}
{assign var="rate" value=1.1}
{assign var="result" value=0}
{math
assign="result"
equation="result + (order_total - commission + discount + delivery_charge) * rate"
result=$result
order_total=$order_total
commission=$commission
discount=$discount
delivery_charge=$delivery_charge
rate=$rate
}
{$result}
If there is any chance to upgrade to Smarty 3 - do it!
Try to use assign
parameter:
From documentation http://www.smarty.net/docsv2/en/language.function.math.tpl :
If you supply the assign attribute, the output of the {math} function will be assigned to this template variable instead of being output to the template.
But it would be better, if you had made similar calculations using PHP (at business-logic layer, not at view)
See http://www.smarty.net/best_practices (section "Keep business logic separate!")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With