开发者

How to calculate totals with smarty php

I have a list of "before discount" prices on my checkout, I want to calculate the total amount of these in a new div at the bottom.. Any ideas?

What I w开发者_如何学Goant to calculate:

{if $item.Product.formattedListPrice}
<div id="salg" title="Rabatt"></div>
{/if}
<div id="cart2Salg">
{if $item.Product.formattedListPrice}
    <span class="listPrice" title="Opprinnelige prisen">
    {$item.Product.formattedListPrice.$currency}
    </span>
    {else}
    <span class="listPrice">

    </span>

{/if}
</div>

And how I tried to calculate it:

{foreach $item.Product.formattedListPrice.$currency as $savedtotal}
  <div  id="savedtotals"> {$savedtotal.formattedAmount.$currency}</div>
{/foreach}

Thanks.


Usually you will all your data to be already prepared for the template in your business logic. In rare cases though you might want to perform sample calculations related to the formatting where you can you Smarty's math function.

For your current case you can use:

{math equation="x * y" x=$savedtotal.formattedAmount y=$currency format="%.2f"}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜