Kabengwa Patrick
Kabengwa Patrick

Reputation: 369

How to add up the prices on the order page in shopware

I have overridden the order page in shopware and i want to create a total of all the orders that not yet been processed. i have wtitten this to just show the variables that i need. i want to add up all the totals of the invoice_amount of the orders.

{extends file="parent:frontend/account/orders.tpl"}

{block name="frontend_account_orders_welcome"}
    {$smarty.block.parent}
    {debug}
    <ul>
        {foreach $sOpenOrders as $sOpenOrder}
        <li> Order number :{$sOpenOrder['ordernumber']}</li>
        <li> User ID :{$sOpenOrder['userID']}</li>
        <li> Invoice_amount :{$sOpenOrder['invoice_amount']}</li>
        <li> ordertime : {$sOpenOrder['ordertime']}</li>
        <li> paymentID : {$sOpenOrder['paymentID']}</li>
        <hr>
        {/foreach}
    </ul> 
{*show here the total of the prices for the the products above something like $Total=[invoice_amount_1+invoice_amount_2]*}
{/block}

Any ideas on how to do that? Am a bit new to shopware and smarty

Upvotes: 0

Views: 379

Answers (3)

mnaczenski
mnaczenski

Reputation: 1626

It might be easier to calculate the total amount directly in php and assign it to the view. Smarty is a template engine - even when it enables you to do calculations and much more (unsafer) stuff, you should do it in php. Instead of including the account-view, it might be the best way to write a plugin, that assigns the open orders to the view.

Upvotes: 0

Kabengwa Patrick
Kabengwa Patrick

Reputation: 369

Finally got what i wanted.

{extends file="parent:frontend/account/orders.tpl"}

{block name="frontend_account_orders_welcome"}
    {$smarty.block.parent}
    {$sOrderTotal = 0}
    <ul>
        {foreach $sOpenOrders as $sOpenOrder}
        <li> Order number :{$sOpenOrder['ordernumber']}</li>
        <li> User ID :{$sOpenOrder['userID']}</li>
        <li> Invoice_amount :{$sOpenOrder['invoice_amount']}</li>
        {assign var="sum_cost" value=$sum_cost+$sOpenOrder.invoice_amount}{*this is besically just declaring a variable and then adding up all the values through the loop*}
        <li> ordertime : {$sOpenOrder['ordertime']}</li>
        <li> paymentID : {$sOpenOrder['paymentID']}</li>
        <hr>
        {/foreach}
    </ul> 
<p>Total cost of all orders : {$sum_cost}</p>
{/block}

Upvotes: 1

FoulFoot
FoulFoot

Reputation: 654

I'm not familiar with this application either, but this should work:

    {extends file="parent:frontend/account/orders.tpl"}

    {block name="frontend_account_orders_welcome"}
        {$smarty.block.parent}
        {debug}
        {$sOrderTotal = 0}
        <ul>
            {foreach $sOpenOrders as $sOpenOrder}
            <li> Order number :{$sOpenOrder['ordernumber']}</li>
            <li> User ID :{$sOpenOrder['userID']}</li>
            <li> Invoice_amount :{$sOpenOrder['invoice_amount']}</li>
            {$sOrderTotal += $sOpenOrder['invoice_amount']}
            <li> ordertime : {$sOpenOrder['ordertime']}</li>
            <li> paymentID : {$sOpenOrder['paymentID']}</li>
            <hr>
            {/foreach}
        </ul> 
    <p>{$sOrderTotal}</p>
    {/block}

I added three lines.

Upvotes: 0

Related Questions