Post by CEMinistries » 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:

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()) + '&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()),
		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('');

				$('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('');
Last edited by CEMinistries on Wed Dec 09, 2015 10:03 pm, edited 3 times in total.

New member

Posts

Joined
Wed Apr 16, 2014 11:17 pm

Post by inactiveaccount9912 » Wed Dec 02, 2015 4:44 am

That looks ok, do you get the field in catalog/controller/api/order.php in the History method? Is it empty or not existing?

Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am

Post by CEMinistries » Wed Dec 02, 2015 10:59 pm

Oh! I did not realize that existed. I have added it to that function. I also found that I forgot to add it to the checkout/order.php file. I have done so, and now I receive a "0" in the database, rather than what I have typed in.

I have attached my vqmod for convenience.

Attachments


New member

Posts

Joined
Wed Apr 16, 2014 11:17 pm

Post by CEMinistries » Mon Dec 07, 2015 10:58 pm

Anybody know why I receive a "0" as the output rather than my input?

New member

Posts

Joined
Wed Apr 16, 2014 11:17 pm

Post by CEMinistries » Tue Dec 08, 2015 11:32 pm

So I found out today that the "check_number" form is sending its data to the "notify" column in Opencart whereas the "notify" input box is sending its data to the custom "check_number" column.

Anyone know why my code is making it switch data?

New member

Posts

Joined
Wed Apr 16, 2014 11:17 pm

Post by inactiveaccount9912 » Wed Dec 09, 2015 6:22 pm

Because of this line:

Code: Select all

$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.

Expert Member

Posts

Joined
Fri May 14, 2010 2:36 am

Post by CEMinistries » Wed Dec 09, 2015 10:02 pm

Thanks so much!!!! That fixed it!

New member

Posts

Joined
Wed Apr 16, 2014 11:17 pm
Who is online

Users browsing this forum: darkhorse and 96 guests