[Answered] Trouble adding custom field to order history
Posted: Wed Dec 02, 2015 1:23 am
Hello all,
I am attempting to add a custom field to the order history. I have successfully edited the language, model, and controller files. I have also added the field into my order_history database, mimicking the "comment" field. However, I am having trouble getting the json script at the end of the tpl file to add the custom field to the database.
Please see codes below.
WORKING: Adding the form to the tpl:
NOT WORKING: Adding the check_number to the JSON script:
WORKING: Clearing the input values:
I am attempting to add a custom field to the order history. I have successfully edited the language, model, and controller files. I have also added the field into my order_history database, mimicking the "comment" field. However, I am having trouble getting the json script at the end of the tpl file to add the custom field to the database.
Please see codes below.
WORKING: Adding the form to the tpl:
Code: Select all
<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>
NOT WORKING: Adding the check_number to the JSON script:
Code: Select all
$('#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) + '&check_number=' + encodeURIComponent($('textarea[name=\'check_number\']').val()) + '&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('');
$('textarea[name=\'check_number\']').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);
}
});
});
WORKING: Clearing the input values:
Code: Select all
$('textarea[name=\'check_number\']').val('');