doukang8949 2015-12-08 17:38
浏览 29
已采纳

为什么我的输入会转到Opencart 2.x中错误的数据库列?

I am attempting to add a custom field to my Order History in Opencart 2.x However, my custom field is sending the data to the wrong database column.

I have added "check_number" as my new field. Somehow "check_number" is sending its data to the "notify" column in the order_history database. "notify" is sending its data to the "check_number" column. See pictures below for reference: order_history table order_info.php

Why is the data being switched? I can't find the error in my code which is sending the data incorrectly.

This is my vqmod file with all the changes:

<file name="admin/model/sale/order.php">
    <operation error="skip">
        <search position="replace"><![CDATA[
        $query = $this->db->query("SELECT oh.date_added, os.name AS status, oh.comment, oh.notify FROM " . DB_PREFIX . "order_history oh LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id WHERE oh.order_id = '" . (int)$order_id . "' AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.date_added ASC LIMIT " . (int)$start . "," . (int)$limit);
        ]]></search>
        <add><![CDATA[
        $query = $this->db->query("SELECT oh.date_added, os.name AS status, oh.comment, oh.check_number, oh.notify FROM " . DB_PREFIX . "order_history oh LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id WHERE oh.order_id = '" . (int)$order_id . "' AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.date_added ASC LIMIT " . (int)$start . "," . (int)$limit);
        ]]></add>
    </operation>
</file>
<file name="admin/controller/sale/order.php">
    <operation error="skip">
        <search position="after"><![CDATA[
        $data['entry_notify'] = $this->language->get('entry_notify');
        ]]></search>
        <add><![CDATA[
        $data['entry_check_number'] = $this->language->get('entry_check_number');
        ]]></add>
    </operation>
    <operation error="skip">
        <search position="after"><![CDATA[
        $data['column_notify'] = $this->language->get('column_notify');
        ]]></search>
        <add><![CDATA[
        $data['column_check_number'] = $this->language->get('column_check_number');
        ]]></add>
    </operation>
    <operation error="skip">
        <search position="after"><![CDATA[
        'notify'     => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'), 
        ]]></search>
        <add><![CDATA[
        'check_number'     => $result['check_number'],
        ]]></add>
    </operation>
</file>
<file name="catalog/model/checkout/order.php">
    <operation error="skip">
    <search position="replace"><![CDATA[
        public function addOrderHistory($order_id, $order_status_id, $comment = '', $notify = false) {
        ]]></search>
        <add><![CDATA[
        public function addOrderHistory($order_id, $order_status_id, $comment = '', $notify = false, $check_number = '') {
        ]]></add>
    </operation>
    <operation error="skip">
    <search position="replace"><![CDATA[
        $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notify . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
        ]]></search>
        <add><![CDATA[
        $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notify . "', comment = '" . $this->db->escape($comment) . "', check_number = '" . $this->db->escape($check_number) . "', date_added = NOW()");
        ]]></add>
    </operation>        
</file>
<file name="catalog/controller/api/order.php">
    <operation error="skip">
    <search position="after"><![CDATA[
        'notify',
        ]]></search>
        <add><![CDATA[
        'check_number',
        ]]></add>
    </operation>
    <operation error="skip">
    <search position="replace"><![CDATA[
        $this->model_checkout_order->addOrderHistory($order_id, $this->request->post['order_status_id'], $this->request->post['comment'], $this->request->post['notify']);
        ]]></search>
        <add><![CDATA[
        $this->model_checkout_order->addOrderHistory($order_id, $this->request->post['order_status_id'], $this->request->post['comment'], $this->request->post['check_number'], $this->request->post['notify']);
        ]]></add>
    </operation>        
</file>
<file name="admin/language/english/sale/order.php">
    <operation error="skip">
    <search position="after"><![CDATA[
        $_['column_notify']            = 'Customer Notified';
        ]]></search>
        <add><![CDATA[
        $_['column_check_number']      = 'Check Number';
        ]]></add>
    </operation>
    <operation error="skip">
    <search position="after"><![CDATA[
        $_['entry_notify']             = 'Notify Customer';
        ]]></search>
        <add><![CDATA[
        $_['entry_check_number']      = 'Check Number';
        ]]></add>
    </operation>        
</file>
<file name="admin/view/template/sale/order_info.tpl">
    <operation error="skip">
    <search position="replace" offset="2"><![CDATA[
        <input type="checkbox" name="notify" value="1" id="input-notify" />
        ]]></search>
        <add><![CDATA[
        <input type="checkbox" name="notify" value="1" id="input-notify" />
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="input-check_number"><?php echo $entry_check_number; ?></label>
              <div class="col-sm-10">
                <textarea name="check_number" rows="1" id="input-check_number" class="form-control"></textarea>
              </div>
            </div>
        ]]></add>
    </operation>
    <operation error="skip">
    <search position="replace"><![CDATA[
        data: 'order_status_id=' + encodeURIComponent($('select[name=\'order_status_id\']').val()) + '&notify=' + ($('input[name=\'notify\']').prop('checked') ? 1 : 0) + '&append=' + ($('input[name=\'append\']').prop('checked') ? 1 : 0) + '&comment=' + encodeURIComponent($('textarea[name=\'comment\']').val()),
        ]]></search>
        <add><![CDATA[
        data: 'order_status_id=' + encodeURIComponent($('select[name=\'order_status_id\']').val()) + '&notify=' + ($('input[name=\'notify\']').prop('checked') ? 1 : 0) + '&append=' + ($('input[name=\'append\']').prop('checked') ? 1 : 0) + '&check_number=' + encodeURIComponent($('textarea[name=\'check_number\']').val()) + '&comment=' + encodeURIComponent($('textarea[name=\'comment\']').val()),
        ]]></add>
    </operation>
    <operation error="skip">
    <search position="after"><![CDATA[
        $('textarea[name=\'comment\']').val('');
        ]]></search>
        <add><![CDATA[
        $('textarea[name=\'check_number\']').val('');
        ]]></add>
    </operation>        
</file>
<file name="admin/view/template/sale/order_history.tpl">
    <operation error="skip">
    <search position="after"><![CDATA[
        <td class="text-left"><?php echo $column_comment; ?></td>
        ]]></search>
        <add><![CDATA[
        <td class="text-left"><?php echo $column_check_number; ?></td>
        ]]></add>
    </operation>
    <operation error="skip">
    <search position="after"><![CDATA[
        <td class="text-left"><?php echo $history['comment']; ?></td>
        ]]></search>
        <add><![CDATA[
        <td class="text-left"><?php echo $history['check_number']; ?></td>
        ]]></add>
    </operation>
</file>
  • 写回答

1条回答 默认 最新

  • dongshan4518 2015-12-09 14:05
    关注

    Answer found on Opencart Forums:

    $this->model_checkout_order->addOrderHistory($order_id, $this->request->post['order_status_id'], $this->request->post['comment'], $this->request->post['check_number'], $this->request->post['notify']);
    

    Check number is 3rd parameter given while in the method notify is 3rd and checknumber is 4th. This needs to be switched to:

    $this->model_checkout_order->addOrderHistory($order_id, $this->request->post['order_status_id'], $this->request->post['comment'], $this->request->post['notify'], $this->request->post['check_number']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?