Post by sariful » Thu Jan 19, 2017 3:28 am

How do i add a extra form field in checkout page under delevery method section ?
Is there any possible option for that without installing any extension.
Thanks

Newbie

Posts

Joined
Wed Jan 18, 2017 7:36 pm


Post by OpenCart Addons » Thu Jan 19, 2017 10:33 am

You would either need to purchase a mod that allows you to do this, or modify the system yourself.

If you're going to modify the system yourself, you will need to start by adding a new column to the order table in the database. This is where your new field information will be stored.

You would then need to edit your files to add the new field, as well as save the data of this field. To do this, edit the following files:

catalog/view/theme/default/template/checkout/shipping_method.tpl
This is where you would add the new field.

Code: Select all

<input type="text" name="your_field" value="<?php echo $your_field; ?>" class="form-control" />
catalog/controller/checkout/shipping_method.php
This is where you would capture the value that the customer has added. You would then save this value as a session variable similar to how the comment is saved.

Code: Select all

if (isset($this->session->data['your_field'])) {
			$data['your_field'] = $this->session->data['your_field'];
		} else {
			$data['your_field'] = '';
		}
Within the function "save" you would need to save your field data. Find:

Code: Select all

$this->session->data['comment'] = strip_tags($this->request->post['comment']);
Add After:

Code: Select all

$this->session->data['your_field'] = strip_tags($this->request->post['your_field']);
catalog/controller/checkout/confirm.php
Send this field data to the add order function so that it's saved to the database

Find:

Code: Select all

$order_data['comment'] = $this->session->data['comment'];
Add After:

Code: Select all

$order_data['your_field'] = $this->session->data['your_field'];
catalog/model/checkout/order.php
Within the addOrder function, you need to push your new field data to the database.

Find:

Code: Select all

, comment = '" . $this->db->escape($data['comment']) . "'
Add After Inline:

Code: Select all

, your_field = '" . $this->db->escape($data['your_field']) . "'
This should be enough to capture the information. You would still need to modify your admin panel to display this new field on the orders detail page.

Please note that I have not tested any of the code examples above.


Cheers,
Joel.

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by suraj_sella » Mon Jan 15, 2018 2:26 am

I followed the same procedure but i am getting error of json unidentified index "your_field" in the line $this->session->data['your_field'] = strip_tags($this->request->post['your_field'])]; in the controller/checkout/payment_method.php file. please guide me.

User avatar
New member

Posts

Joined
Wed Nov 22, 2017 3:57 pm

Post by cahb52 » Thu May 17, 2018 1:48 am

i apply this method with opencart 3 the unique diference is the view file, in version 3 is a twig file and not a tpl file.
but i have one problem. the form shows the fields, but this fields are not saved into the database. the problem is that they are not added to the array
can you help me please?
Image

Newbie

Posts

Joined
Wed May 16, 2018 11:43 pm
Who is online

Users browsing this forum: No registered users and 7 guests