订单历史记录中的OpenCart自定义字段

时间:2015-10-20 13:04:31

标签: php sql opencart2.x

订单历史OC 2.0.3.1中的自定义字段

尝试在订单历史记录中插入两个自定义字段。我已完成以下代码编辑并手动输入两列到数据库(tracking_number和check_number),它不起作用。我没有收到任何错误,所以我不确定我做错了什么。任何帮助,将不胜感激。

在我的order_history.tpl文件中,我添加了:

<td class="text-left"><?php echo $history['tracking_number']; ?></td>
<td class="text-left"><?php echo $history['check_number']; ?></td>

<td class="text-left"><?php echo $column_tracking_number; ?></td>
<td class="text-left"><?php echo $column_check_number; ?></td>

在我的order_info.tpl文件中,我添加了:

<div class="form-group">
              <label class="col-sm-2 control-label" for="input-tracking-number"><?php echo $entry_tracking_number; ?></label>
              <div class="col-sm-10">
                <input type="text" name="tracking_number" id="input-tracking-number" size="50" />
              </div>
            </div>
                                                                             

在我的控制器order.php文件中,我将正确的语言文件添加到历史数组中:

'tracking_number'     => $result['tracking_number'], 
'check_number'     => $result['check_number'],

在我的模型order.php文件中,我更改了以下内容:

$query = $this->db->query("SELECT oh.date_added, os.name AS status, oh.comment, oh.tracking_number,  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);
/ checkout / order.php

$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) . "', tracking_number = '" . (int)$tracking_number . "', date_added = NOW()");

public function addOrderHistory($order_id, $order_status_id, $comment = '', $tracking_number = '', $notify = false) {
  $this->event->trigger('pre.order.history.add', $order_id);

现在是&#34; 0&#34;无论如何都会出现在tracking_number字段中。

2 个答案:

答案 0 :(得分:0)

只需从插入查询中删除(int)即可。如果您的跟踪号码是字母数字形式。您的插入查询应如下所示:

$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) . "', tracking_number = '" . $this->db->escape($tracking_number) . "', date_added = NOW()");

就是这样。

答案 1 :(得分:0)

不要忘记将它添加到catalog / controller / api / order.php文件中的History函数中。

寻找代码:

$keys = array(
            'order_status_id',
            'notify',
            'append',
            'comment'
        );

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

您可能还需要将它添加到AJAX json脚本中order_info.tpl文件的底部:

$('#button-history').on('click', function() {
if(typeof verifyStatusChange == 'function'){
if(verifyStatusChange() == false){
  return false;
}else{
  addOrderInfo();
}
}else{
addOrderInfo();
}

$.ajax({
    url: 'index.php?route=sale/order/api&token=<?php echo $token; ?>&api=api/order/history&order_id=<?php echo $order_id; ?>',
    type: 'post',
    dataType: 'json',
    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()),
    beforeSend: function() {
        $('#button-history').button('loading');         
    },
    complete: function() {
        $('#button-history').button('reset');   
    },
    success: function(json) {
        $('.alert').remove();

        if (json['error']) {
            $('#history').before('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
        } 

        if (json['success']) {
            $('#history').load('index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>');

            $('#history').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

            $('textarea[name=\'comment\']').val('');

            $('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());          
        }           
    },          
    error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
});
});