Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 订单历史记录中的OpenCart自定义字段_Php_Sql_Opencart2.x - Fatal编程技术网

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

Php 订单历史记录中的OpenCart自定义字段,php,sql,opencart2.x,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']; ?>&l

订单历史记录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>
在我的model 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()");

现在,无论发生什么情况,跟踪编号字段中都会出现一个0。

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

$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()");

就这样。

别忘了将其添加到catalog/controller/api/order.php文件中的History函数中

查找代码:

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

您可能还需要将其添加到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);
    }
});
});

字段tracking_number的数据类型是什么?这是航运公司提供的唯一编号..示例:BHC21315457896154非常感谢您的帮助,我以前尝试过删除int,但结果值SQL字段始终为0
public function addOrderHistory($order_id, $order_status_id, $comment = '', $tracking_number = '', $notify = false) {
  $this->event->trigger('pre.order.history.add', $order_id);
$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()");
$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']);
$('#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);
    }
});
});