views:

87

answers:

1

Hi, 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.

+1  A: 

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"}
Ivo Sabev
Thanks, how do I use the X * Y part though? Sorry, this is totally new to me :) What should I put in there?
Kyle Sevenoaks
The equation attribute defines what calculation you want to perform. Basically you set the names of the variables there and how will they interact. Then you need to create attributes with the same names X and Y like I showed you and assign them real values.Copy paste this: {math equation="x + y" x=2 y=2} and experiment to see how it works.
Ivo Sabev