Kyle
Kyle

Reputation: 67194

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 want 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.

Upvotes: 1

Views: 6195

Answers (1)

Ivo Sabev
Ivo Sabev

Reputation: 5230

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"}

Upvotes: 3

Related Questions