在Opencart的“订单信息"页面上添加自定义字段 [英] Add a Custom Field on Opencart admin 'Order Info' page

查看:238
本文介绍了在Opencart的“订单信息"页面上添加自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在opencart管理员订单页面上添加自定义字段.

I want to add custom field on opencart admin order pages.

  1. 比较值,例如oc_order.order_id = oc_custom_table.order_id,然后在管理订单列表上显示oc_custom_table.comment.
  2. 在管理订单信息页面上显示相同的内容.
  1. compare value like if oc_order.order_id = oc_custom_table.order_id then display oc_custom_table.comment on admin order list.
  2. display same thing on admin order info page.

我在admin_model_order.php页面中添加了一个自定义函数,其中所有查询均存在.

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.

在语言中,我只需要定义语言变量,例如$ _text_custom_variable ='test';.正确的?和模板文件,我只是选择一个位置来显示值.

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.

我正在使用Opencart 2.0版本.

I am using Opencart 2.0 version.

:好的,我能够通过引用vqmod之一来编写VQMOD,但仍然无法提取数据.我收到错误Trying to get property of non-object

: 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>

推荐答案

我自己就能弄清楚这一点.这就是我的理解.我可能错了,但是简单的代码有效.

I was able to figure this out myself. And this is what I understood. I maybe wrong but the simple code worked.

我正在管理顺序"部分进行更改,弄清楚更改所用的方法很重要.对于模型"部分,请使用适当的方法并添加查询或编辑当前查询.与控制器相同.如果您尝试显示为列表-order_list(getList())或order_info(getInfo)部分.对于擅长此操作的人来说可能很简单,但是对我来说,这是我的第一次,所以花了很多时间.

I was doing changes in Admin order section and it is important to figure out which method the change is being done in. For Model section, use apropriate method and add query or edit present query. Same with Controller. If you are trying to display as a list - order_list(getList()) or order_info(getInfo) section. It may be simple to people who are good at it but for me, this was my first, so it took lot of time.

下面是VQMOD格式的工作代码.

below is the working code in VQMOD format.

<modification>
  <id><![CDATA[custom order list]]></id>
    <version>1</version>
    <vqmver>2.X</vqmver>
    <author>customAuthor</author>
    <file name="admin/language/english/sale/order.php">
         <operation>
            <search position="after"><![CDATA[
            $_['text_order_id']                           = 'Order ID:';
            ]]></search>
            <add><![CDATA[
            $_['text_custom_order_number']                           = 'custom:';
            ]]></add>
        </operation>
        <operation>
            <search position="after"><![CDATA[
            $_['column_order_id']                         = 'Order ID';
            ]]></search>
            <add><![CDATA[
            $_['column_custom_order_number']                         = 'custom <i class="fa fa-shopping-cart"></i>';
            ]]></add>
        </operation>

    </file>
    <file name="admin/view/template/sale/order_list.tpl">

        <operation>
            <search position="after"><![CDATA[
            <a href="<?php echo $sort_order; ?>"><?php echo $column_order_id; ?></a>
            ]]></search>
            <add><![CDATA[
            <!-- custom -->
                    <td class="text-left">
                        <?php echo $column_custom_order_number; ?></a>
                    </td>

            <!-- custom -->
            ]]></add>
        </operation>
        <operation>
            <search position="after"><![CDATA[
            <td class="text-right"><?php echo $order['order_id']; ?></td>
            ]]></search>
            <add><![CDATA[
            <td class="text-left"><?php if(!empty($order['cu_orders'])){echo "CU".$order['cu_orders'];} else{echo "  ";} ?></td>
            ]]></add>
        </operation>

    </file>
    <file name="admin/view/template/sale/order_info.tpl">

        <operation>
            <search position="after" offset="1"><![CDATA[
            <td>#<?php echo $order_id; ?></td>
            ]]></search>
            <add><![CDATA[
            <!-- Shopgate -->
                    <tr>
                        <td><?php echo $text_custom_order_number; ?></td>
                        <td><?php if (!empty($custom_order_number)) { ?>
                          <?php echo 'CU'.$custom_order_number; ?>
                          <?php } else { ?>
                          <?php echo " "; ?> 
                          <?php } ?>
                        </td>

                    </tr>

            <!-- Shopgate -->
            ]]></add>
        </operation>         
    </file>
    <file name="admin/model/sale/order.php">
    <!-- getOrder() Modifications -->
        <operation>
            <search position="replace"><![CDATA[
            (SELECT CONCAT(c.firstname, ' ', c.lastname) FROM " . DB_PREFIX . "customer c WHERE c.customer_id = o.customer_id) AS customer
            ]]></search>
            <add><![CDATA[
            (SELECT CONCAT(c.firstname, ' ', c.lastname) FROM " . DB_PREFIX . "customer c WHERE c.customer_id = o.customer_id) AS customer, (SELECT s.custom_order_number FROM " . DB_PREFIX . "custom_orders s WHERE s.custom_order_number = o.order_id) AS custom_order_number 
            ]]></add>
        </operation>
        <operation>
            <search position="after"><![CDATA[
            'order_id'                => $order_query->row['order_id'],
            ]]></search>
            <add><![CDATA[
            'custom_order_number'                => $order_query->row['custom_order_number'],
            ]]></add>
        </operation>
        <!-- getOrderS() Modifications -->
        <operation>
            <search position="replace"><![CDATA[
            CONCAT(o.firstname, ' ', o.lastname) AS customer,
            ]]></search>
            <add><![CDATA[
            CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT s.custom_order_number FROM " . DB_PREFIX . "custom_orders s WHERE s.custom_order_number = o.order_id) AS custom_order_number,
            ]]></add>
        </operation>

    </file> 
    <file name="admin/controller/sale/order.php">   
    <!-- getList() Modifications -->
        <operation>
            <search position="after"><![CDATA[
                'order_id'      => $result['order_id'],
            ]]></search>
            <add><![CDATA[
                'cu_orders'      => $result['custom_order_number'], 
            ]]></add>
        </operation>
    <!-- getForm() Modifications -->
        <operation>
            <search position="after"><![CDATA[
                $data['store_id'] = $order_info['store_id'];
            ]]></search>
            <add><![CDATA[
                $data['custom_order_number'] = $order_info['custom_order_number'];
            ]]></add>
        </operation>
        <!-- getInfo() Modifications -->
        <operation>
            <search position="after"><![CDATA[
                $data['text_order_id'] = $this->language->get('text_order_id');
            ]]></search>
            <add><![CDATA[
                $data['text_custom_order_number'] = $this->language->get('text_custom_order_number');
            ]]></add>
        </operation>
        <operation>
            <search position="after"><![CDATA[
                $data['store_name'] = $order_info['store_name'];
            ]]></search>
            <add><![CDATA[
                $data['custom_order_number'] = $order_info['custom_order_number'];
            ]]></add>
        </operation>

    </file>         
</modification>

这篇关于在Opencart的“订单信息"页面上添加自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆