Jump to content

Сумма заказов пользователя


Go to solution Solved by Kosjak76,

Recommended Posts

Подскажите как вывести сумму всех заказов пользователя:

{if $orders}    <h3>Всего заказов на сумму:    	{foreach $orders as $order}            {$order->total_price}        {/foreach}    </h3>{/if}

Как суммировать все числа массива на smarty, не специалист, но поиск такое выдает 2(((
Link to post
Share on other sites

Да, в админку напротив пользователя в user.tpl
Получается код в user.tpl:

{foreach $orders as $order}            {$order->total_price}        {/foreach}

Выводит суммы заказов пользователя, числами:
100020.00
2050.00
32650.00
Проблема как их сложить, реально был бы хоть пример какой-нибудь...
Жду помощи!!!
Link to post
Share on other sites
  • 1 year later...

 



{assign var="sum" value="0"}
{foreach $orders as $order}
		{if $order->paid}
            {$sum = $sum +$order->total_price}
		{/if}
        {/foreach}
{if $sum >0}Сумма оплаченных заказов: {$sum|convert}{/if}

спасибо большое все работает !

Link to post
Share on other sites

simpla/design/html/orders.tpl, место - по Вашему усмотрению, например, в начале

Странно я почему то думал что надо править файл user.tpl 

и если даже в orders.tpl вставить кусок этого скриапта, то заказы в админке падают и страница не открывается.

Link to post
Share on other sites
  • 8 months later...

Не много по другому сделал используя JS

 

<h2>Заказы пользователя - <label id="result"></label> {$currency->sign}</h2>

{literal}
<script>
    $(document).ready(function(){
	var total = 0;
	$('div #price').each(function(){       
        total += Number($(this).text());
     });
	
	$('#result').html( total );
    });
</script>
{/literal}
Link to post
Share on other sites
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...