I want to add custom field on opencart admin order pages.
- compare value like if
oc_order.order_id
=oc_custom_table.order_id
then displayoc_custom_table.comment
on admin order list. - display same thing on admin order info page.
I added a custom function in admin_model_order.php page where there all all queries.
public function getCustomTable($order_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "custom_table WHERE order_id = '" . (int)$order_id . "'"); return $query->rows; }
The controller page is pretty crowded and i have no idea where to add variables so it displays order specific info.
In the language, I just have to define language variables like $_text_custom_variable = 'test'; right? and template files, I just choose a place to display the value.
I am using Opencart 2.0 version.
[EDIT]: Okay so i was able to write a VQMOD by referencing one of the vqmod for it but still cannot pull up data. I get error Trying to get property of non-object
I tried first adding the data in order list.
<!--Template File -->
<file name="admin/view/template/sale/order_list.tpl">
<operation>
<search position="before"><![CDATA[
<td class="text-left"><?php echo $order['date_added']; ?></td>
]]></search>
<add><![CDATA[
<td class="text-right"><?php echo 'CO'. $order['custom_orders'];?></td>
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[
<td class="text-left"><?php if ($sort == 'o.date_added') { ?>
]]></search>
<add><![CDATA[
<td class="text-right">custom orders <i class="fa fa-shopping-cart"></i></td>
]]></add>
</operation>
</file>
<!--Model File -->
<file name="admin/model/sale/order.php">
<operation>
<search position="before"><![CDATA[
public function getTotalEmailsByProductsOrdered($products) {
]]></search>
<add><![CDATA[
public function getCustomOrderNumber($order_id) {
$custom_orders ='';
$query = $this->db->query("SELECT o.order_id, s.external_order_number, s.custom_order_number
FROM oc_order o
LEFT JOIN " . DB_PREFIX . "custom_orders s ON (s.external_order_number = o.order_id)
WHERE o.order_id = '" . (int)$order_id . "'");
foreach ($query->rows as $row) {
$custom_orders += $this->custom_orders->$row['custom_orders'];
}
return $custom_orders;
}
]]></add>
</operation>
</file>
<!--Controller File -->
<file name="admin/controller/sale/order.php">
<operation>
<search position="before"><![CDATA[
'delete' => $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
]]></search>
<add><![CDATA[
'custom_orders' => $this->model_sale_order->getCustomOrderNumber($result['order_id']),
]]></add>
</operation>
</file>