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

Post by meb.webmaster » Mon May 27, 2019 10:22 pm

Hello everyone,

I managed to eliminate all the steps related to shipping since my company coordinates it separately directly with the client but in the payment methods I added two input so that the user can also indicate if he is going to agree on a shipment later or if he is going to withdraw in store as to anticipate that management. In this case instead of editing on the "shipping_method.php" I had to do on the "payment_method.php" in the same way that is described here and it worked perfectly.

This post was very useful for me and I wanted to give the credit to "OpenCart Addons" for its careful response.

Newbie

Posts

Joined
Mon May 27, 2019 10:08 pm

Post by AdieB » Tue Feb 11, 2020 7:09 pm

I managed to get this working on adding an additional form field on payment_address.tpl and it is working well. A few minor changes but thanks for a very helpful article. I spent two days trying to get it to work before I found this.
All credit to the author.
v2.3.0.2

New member

Posts

Joined
Mon May 19, 2014 9:01 pm
Who is online

Users browsing this forum: No registered users and 23 guests