How To Sum The Values I Sort At Orders Page

I calculated some values and saved these data into orders database. I sort these values at the orders page. I want sum these data like “Gross total” at the bottom.



Here is the code I use in orders.post.php:

<br />
if ($mode == 'manage') {<br />
$orders = Registry::get('view')->getTemplateVars('orders');<br />
		foreach ($orders as $k => $d) {<br />
				$orders[$k]['profit'] = db_get_field("SELECT profit FROM ?:orders WHERE order_id = ?i",$d['order_id']);<br />
		}<br />
		Registry::get('view')->assign('orders', $orders);<br />
}<br />

```<br />
<br />
How to sum the values I am sorting at Orders Page? what is the way?<p><a href="127.0.0.1/uploads/monthly_04_2015/post-20511-0-94453400-1428765941.jpg">ss.jpg</a></p>

I’ve found the way how to do, but something is wrong. I need help.



I found that I should use “get_orders_totals” hook in fn.cart.php.


<br />
function fn_cce_muhasebe_get_orders_totals(&$paid_statuses, &$join, &$condition, &$group)<br />
{<br />
  $my_order_statuses = array('C','W','R','S','L','K','Y','J','O','P','M');<br />
<br />
  $totals = array (<br />
   'net_kar' => db_get_field("SELECT sum(t.net_kar) FROM ( SELECT net_kar FROM ?:orders $join WHERE ?:orders.status IN (?a) $condition $group) as t", $my_order_statuses),<br />
);<br />
<br />
  Registry::get('view')->assign('totals', $totals);<br />
<br />
}<br />

```<br />
<br />
Above is the code I use in func.php in my addon. The problem is: when I add<br />
```php
<br />
Registry::get('view')->assign('totals', $totals);<br />

```<br />
<br />
"gross_total" and "totally_paid" variables become '0' in orders/manage.tpl. <img src="upload://n4syhXZrRhsStKvmS4jT3Mp2S3k.png" class="bbc_emoticon" alt=":(">

hi,


[quote][color=#282828][font=arial, verdana, tahoma, sans-serif]“gross_total” and “totally_paid” variables become ‘0’ in orders/manage.tpl. [/font][/color] :([color=#282828][font=arial, verdana, tahoma, sans-serif] [/font][/color][/quote]



the issue is that $totals variable is already reserved and used for bottom statistics on this page. when you re-assign it in PHP hook, it is completely ovewritten and old values are reset





we advise to use PHP post controller for this mod - “app/addons/your_module/controllers/backend/orders.post.php”:

<br />
<?php<br />
<br />
<br />
use Tygh\Registry;<br />
<br />
if (!defined('BOOTSTRAP')) { die('Access denied'); }<br />
<br />
if ($mode == 'manage') {<br />
    $my_order_statuses = array('C','W','R','S','L','K','Y','J','O','P','M');<br />
    $totals = Registry::get('view')->getTemplateVars('totals')<br />
<br />
    $totals['net_kar'] = db_get_field("SELECT sum(t.net_kar) FROM ( SELECT net_kar FROM ?:orders $join WHERE ?:orders.status IN (?a) $condition $group) as t", $my_order_statuses);<br />
<br />
    Registry::get('view')->assign('totals', $totals);<br />
}<br />

```<br />
<br />
<br />
<br />
to display new value in bottom statistics, please check TPL hook - orders:totals_stats in "design/backend/templates/views/orders/manage.tpl" and it will be available under $totals.net_kar<br />
<br />
best regards,<br />
WSA team