Page 1 of 1

Added extra field to checkout does not save in database

Posted: Tue Mar 08, 2016 6:30 pm
by mediaorb
Hello,

I am using OpenCart 1.5.6.1 and I am trying to add a new field to the payment method section of the checkout, namely "Purchase Order". The field is in the database, and the input box appears in the checkout as it should, but it just does not save to the database like the other fields.

I'm pretty new to this so I'm not sure if I've done it correctly, but in my checkout/confirm.php controller:

Code: Select all

$data['products'] = $product_data;
$data['vouchers'] = $voucher_data;
$data['totals'] = $total_data;
$data['comment'] = $this->session->data['comment'];
$data['purchase_order'] = $this->session->data['purchase_order'];
$data['total'] = $total;
I've added $data['purchase_order'] below comments, but this does not seem to take - even if I hard code the result.

In my checkout/payment_method.php controller:

Code: Select all

$this->data['text_purchase_order'] = $this->language->get('text_purchase_order');

....

if (isset($this->session->data['purchase_order'])) {
     $this->data['purchase_order'] = $this->session->data['purchase_order'];
} else {
     $this->data['purchase_order'] = '';
}
And at the bottom of the same file:

Code: Select all

if (!$json) {
	$this->session->data['payment_method'] = $this->session->data['payment_methods'][$this->request->post['payment_method']];
	$this->session->data['comment'] = strip_tags($this->request->post['comment']);
	$this->session->data['purchase_order'] = trim($this->request->post['purchase_order']);
}	
In my model/checkout/order.php file, I've added the field to the addOrder() function, though that also does not work - however if I hard code that, it does so it must be working there.

But, like I say, the field DOES appear on the checkout, the language file is fine as is the template but it's just the processing of the field which does not work.

If anyone can help me with this I would appreciate it as I'm not 100% sure what I'm doing!

Thank you
Michael

Re: Added extra field to checkout does not save in database

Posted: Tue Mar 08, 2016 10:43 pm
by villagedefrance
I think you have to add some "purchase order" code in the "session" Class, in your System > Library > Session.php file, because you are calling $this->session->data['purchase_order'].

Re: Added extra field to checkout does not save in database

Posted: Tue Mar 08, 2016 11:02 pm
by artcore
I think the payment method is sending the data via ajax so you need to add the variable in the data object of the ajax function.