[英]OpenCart Custom Fields in Order History
Custom Fields in Order History OC 2.0.3.1 订单历史记录OC 2.0.3.1中的自定义字段
Trying to insert two custom fields into the order history. 尝试在订单历史记录中插入两个自定义字段。 I have done the following code edits and manually entered two columns into the database(tracking_number and check_number) and it is not working.
我已经完成了以下代码编辑,并手动将两列输入到数据库中(tracking_number和check_number),但它不起作用。 I am not getting any errors, so I'm not sure what I'm doing wrong.
我没有收到任何错误,所以我不确定自己在做什么错。 Any help would be appreciated.
任何帮助,将不胜感激。
In my order_history.tpl file I added: 在我的order_history.tpl文件中添加了:
<td class="text-left"><?php echo $history['tracking_number']; ?></td>
<td class="text-left"><?php echo $history['check_number']; ?></td>
And 和
<td class="text-left"><?php echo $column_tracking_number; ?></td>
<td class="text-left"><?php echo $column_check_number; ?></td>
In my order_info.tpl file I added: 在我的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>
In my controller order.php file I added the proper language files and this into the history array: 在我的控制器order.php文件中,我添加了正确的语言文件,并将其添加到历史记录数组中:
'tracking_number' => $result['tracking_number'],
'check_number' => $result['check_number'],
In my model order.php file I changed the following: 在我的模型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);
in my checkout/order.php 在我的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()");
And 和
public function addOrderHistory($order_id, $order_status_id, $comment = '', $tracking_number = '', $notify = false) {
$this->event->trigger('pre.order.history.add', $order_id);
Now a "0" appears in the tracking_number field no matter what. 现在无论如何,“ 0”将出现在tracking_number字段中。
Just remove (int)
from your insert query. 只需从插入查询中删除
(int)
。 If your tracking number is in alphanumeric form. 如果您的跟踪号为字母数字形式。 Your insert query should look like :
您的插入查询应类似于:
$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()");
That's it. 而已。
Don't forget to add it to the History function in the catalog/controller/api/order.php file. 不要忘记将其添加到catalog / controller / api / order.php文件中的History功能。
Look for the codes: 查找代码:
$keys = array(
'order_status_id',
'notify',
'append',
'comment'
);
and 和
if ($order_info) {
$this->model_checkout_order->addOrderHistory($order_id, $this->request->post['order_status_id'], $this->request->post['comment'], $this->request->post['notify']);
You may also need to add it to the bottom of the order_info.tpl file in the AJAX json script: 您可能还需要将其添加到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()) + '¬ify=' + ($('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">×</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">×</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);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.