Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty total amount sum

how can I count the final price to pay if I have the following code

$Total

:

 {foreach from=$items key=k item=item}
            <tr>
              <td class="align_left"><strong>{$item.Title}</strong></td>
              <td><a href="products/view/{$k}"><img src="products_images/{$item.ImagePath}" width="60" height="60" alt="{$item.Title}" /></a></td>
              <td>{$item.quantity}</td>
              <td>{$item.Price}<span class="s_currency s_after"> лв.</span></td>
              <td>{math equation="x * y" x=$item.Price y=$item.quantity}<span class="s_currency s_after"> лв.</span></td>
            </tr>              
         {/foreach}
         <tr class="last">
             <td class="align_right" colspan="4"><strong>Всичко:</strong></td>
             <td class="s_secondary_color"><span class="s_currency s_before">$</span>{$Total}</td>
        </tr>
like image 631
Fortran Avatar asked May 26 '26 15:05

Fortran


1 Answers

I did not understand why you need it so, but do it:

NOTICE: for Smarty 3.

{$Total = 0 }  

{foreach from=$items key=k item=item}
        <tr>
          <td class="align_left"><strong>{$item.Title}</strong></td>
          <td><a href="products/view/{$k}"><img src="products_images/{$item.ImagePath}" width="60" height="60" alt="{$item.Title}" /></a></td>
          <td>{$item.quantity}</td>
          <td>{$item.Price}<span class="s_currency s_after"> лв.</span></td>
          <td>{math equation="x * y" x=$item.Price y=$item.quantity}<span class="s_currency s_after"> лв.</span></td>
          {$Total = $Total+ ($item.Price*$item.quantity) }
        </tr>              
     {/foreach}
     <tr class="last">
         <td class="align_right" colspan="4"><strong>Всичко:</strong></td>
         <td class="s_secondary_color"><span class="s_currency s_before">$</span>{$Total}</td>
    </tr>
like image 51
voodoo417 Avatar answered May 28 '26 03:05

voodoo417



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!