Listing Own Values In Orders Manage

What is wrong with this code?



There are invoice numbers that belong to orders that I build in my table. Each order has different invoice number. I want to show these invoice numbers at “dispatch=orders.manage”. But I receive always same results for all orders.





app/addons/MY_ADDON/controllers/backend/orders.post.php

<br />
if ($mode == 'manage') {<br />
<br />
list($orders, $search, $totals) = fn_get_orders($params, Registry::get('settings.Appearance.admin_orders_per_page'), true);<br />
<br />
<br />
  foreach ($orders as $k => $d) {<br />
	  <br />
   $data = db_get_row("SELECT invoice_no FROM ?:cce_order_invoice WHERE order_id = ?i",$d['order_id']);<br />
<br />
	   if (!empty($data)){<br />
	   Registry::get('view')->assign('invoice', $data);<br />
	   }<br />
  <br />
  }<br />
<br />
}<br />

```<br />
<br />
manage_data.post.tpl file<br />
```php
<br />
{if $orders}<td>{$invoice.invoice_no}</td>{/if}<br />

```<br />
<br />
See attachment.<p><a href="127.0.0.1/uploads/monthly_01_2015/post-20511-0-78119300-1421517109.jpg">Untitled-2.jpg</a></p>

Hi @ooaykac,



You don’t need to get the orders again ;) becase the system already get them, you need only to add invoice_no for each order and for this please use the code bellow

use Tygh\Registry;<br />
if ($mode == 'manage') {<br />
	$orders = Registry::get('view')->getTemplateVars('orders');<br />
	foreach ($orders as $k => $d) {<br />
		$orders[$k]['invoice_no'] = db_get_field("SELECT invoice_no FROM ?:cce_order_invoice WHERE order_id = ?i",$d['order_id']);<br />
	}<br />
	Registry::get('view')->assign('orders', $orders);<br />
}
```<br />
<br />
[color=#008000]PS: If this helps you please Vote this post <img src="upload://ssa1U17ndImgNZSdwFNmOF2yUgM.png" class="bbc_emoticon" alt=";)">[/color]<br />
<br />
Regards,<br />
<br />
---<br />
Valentin<br />
[color=#808080][size=2]part of hungryweb.net[/size][/color]

Thank you Vali. Great.

Another question: How to get “tracking_number” of an order? Should I query or is it already exist?



Query like this??

$orders[$k]['tracking_number'] = db_get_row("SELECT ?:shipments.tracking_number FROM ?:shipments ".
"LEFT JOIN ?:shipment_items ON ?:shipment_items.shipment_id = ?:shipments.shipment_id WHERE ?:shipment_items.order_id = ?i",$d['order_id']);

Please use
db_get_field


db_get_row > return array()

db_get_field > return only one field

[quote name='Vali' timestamp='1421651101' post='202891']

Please use
db_get_field


db_get_row > return array()

db_get_field > return only one field

[/quote]

OK I got it. Thanks.