代码之家  ›  专栏  ›  技术社区  ›  Kyle

如何用smarty php计算总数

  •  1
  • Kyle  · 技术社区  · 15 年前

    我在结帐时有一个“折扣前”价格的清单,我想在底部的新分区中计算这些价格的总金额。有什么想法吗?

    我要计算的内容:

    {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>
    

    以及我如何计算它:

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

    谢谢。

    1 回复  |  直到 15 年前
        1
  •  3
  •   Ivo Sabev    15 年前

    通常,您将为业务逻辑中的模板准备好所有数据。在极少数情况下,尽管您可能希望执行与格式相关的示例计算,但您可以在其中智能 math function

    对于您当前的案例,您可以使用:

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