Forums / Templates, Stylesheets, Page Layout / Adding Field to Checkout

Adding Field to Checkout

Views: 31,098

Results 61 to 80 of 84
5 Mar 2009, 2:13 PM
#61
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Adding Field to Checkout

:clap: Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you :clap:

23 Mar 2009, 4:03 PM
#62
eddyboy avatar

eddyboy

New Zenner

Join Date:
Nov 2008
Posts:
18
Plugin Contributions:
0

Re: Adding Field to Checkout

Once again I must ask for help :unsure:

A little background on the site may help.

It is a mobile phone website selling mostly phones under certain tarrifs. I have made a Direct Debit Form that the customer has to fill out (to take monthly payments) when purchasing anything. This is prefect for any of the phones, but it has just occured to me that the customer shouldnt have to fill in this form if they are buying only an accessory (with no monthy payments) which currently they are forced to.

I already have made a modification to the database that marks every product as an Accessory or a Phone product. Could I use this feild to check whether or not the customer is only buying an accessory, and, if they are not show the form or make the form feilds not required?

Presumably the products in the cart are stored in a session variable somewhere, if I could check whats in the cart against the database I could make the Form required or not with some if else statements ?

Thanks in advance for any help/ideas :smile:

11 Feb 2010, 5:21 PM
#63
jdw1979 avatar

jdw1979

Zen Follower

Join Date:
Jun 2009
Location:
NC
Posts:
174
Plugin Contributions:
0

Re: Adding Field to Checkout

Anybody have any idea how I might add a checkbox that will enable users to split the shipment of their product should they desire to do so? I'd have to be able to see it in the orders area of the admin as well. I'm not particularly PHP savvy, in fact, I know just enough to get myself into trouble to be perfectly honest...all I've been able to get done so far is adding a split_shipment field in the orders database...:frusty:

Johnathan D. Walker
Wilburn Medical USA

8 Mar 2010, 7:19 PM
#64
steves14 avatar

steves14

New Zenner

Join Date:
Feb 2010
Posts:
8
Plugin Contributions:
0

Re: Adding Field to Checkout

I need to add a 'pickup time' field to checkout. The time is generated automatically for the customer. I followed the instructions exactly and it just keeps adding blank entries under pickup_time in the database.

$_session['pickup_time'] sees the correct value and so does $order->info['pickup_time'] but $_post doesn't see anything. I know this is the problem, so how can I just set $_post['pickup_time'] to a value?

14 Mar 2010, 8:55 AM
#65
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

@jdw1979 - Avoid this at all costs if you don't have a great knowledge of PHP. You need to consider charges for shipping, which items are being sent to which addresses, which items you mark as dispatched, order statuses etc. It's a pain in the neck to do, and if your customers need this, suggest placing two or more orders.

@SteveS14 - if $_SESSION is showing the right value, then $_POST must have shown it at some point as this is where SESSION gets the value initially. If the $order is also correct then I suggest your problem may be in the order class file where the database value is set within teh array. Look in this file for a zen_db_perform statement which includes TABLE_ORDERS. This will push the array into the database table, and it is this array that you need to print_r to ensure is set correctly.

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

21 Dec 2010, 12:03 AM
#66
sohailarif avatar

sohailarif

New Zenner

Join Date:
Dec 2010
Posts:
10
Plugin Contributions:
0

Re: Adding Field to Checkout

could you please help me with uninstalling sql

CREATE TABLE customers_additional (
field_id int(11) NOT NULL auto_increment,
field_name varchar(255) NOT NULL default '',
field_status char(2) NOT NULL default '',
PRIMARY KEY (field_id)
) ENGINE=MyISAM;

after this patch i have started getting error below

1054 Unknown column 'field_required' in 'field list'
in:
[ SELECT field_id, field_name, field_required, field_status, use_url, field_url FROM customers_additional WHERE field_status = 1 ]

21 Dec 2010, 12:10 AM
#67
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

You don't have a "field_required" column in your database. Without seeing the rest of the code you've added to the site, it's impossible to tell what this field should be. I would guess at either a tinyint if the original creator is using 0 or 1 to depict true/false, or it could be a char(1) field if using Y or N to give but 2 examples.

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

21 Dec 2010, 12:11 AM
#68
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

You're also missing two additional columns: "use_url" & "field_url"

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

21 Dec 2010, 12:17 AM
#69
sohailarif avatar

sohailarif

New Zenner

Join Date:
Dec 2010
Posts:
10
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute:

You're also missing two additional columns: "use_url" & "field_url"

Absolute

Thanks for reply, is there any way to unistall mysql patch to fix this?

21 Dec 2010, 9:54 AM
#70
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Adding Field to Checkout

Uninstalling the SQL patch will make the problem worse, as then there will be more missing data fields.

You need to remove the code that is asking for these fields, or add them. Where did you get the code from?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

19 Jan 2011, 5:11 PM
#71
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute:

There are a couple of ways you can achieve this. Firstly, do you offer frequent buyer discount? If so, the best thing to do is to create a new order_total module, which checks the card validity, and if valid, gives a discount. But thats another topic, related, but different.

Ok, so adding the fields to the checkout.

BACKUP EVERYTHING BEFORE EDITTING ANY OF THESE FILES

Firstly, you need to decide which page you are going to add the field to. If its the shipping page, then edit includes/templates/YOUR ACTIVE TEMPLATE/templates/tpl_checkout_shipping_default.php . If its the payment page, then edit tpl_checkout_payment_default.php in the same folder. Here you just need to add the field.

The field needs to be as follows:

<?php echo zen_draw_input_field('frequent_code'); ?>

Next is the difficult bit.

Firstly, you need to add a new column to the orders database table. Use phpmyadmin, and navigate to the table. Add a new column called order_frequent_code.

Next, alter the order.php class file, found in includes/classes/order.php
There are a fair number of bits to add, but bare with me:

Line 43, add order_frequent_code, to the sql statement.

Line 114, before 'ip_address' insert the following line:
'frequent_code' => $order->fields['order_frequent_code'],

Line 343, before 'ip_address' insert the following line:
'frequent_code' => $_SESSION['frequent_code'],

Line 587, before 'ip_address', insert the following line:
'order_frequent_code' => $this->info['frequent_code'],

Ok, nearly there. So far, we've added the field to the template, added the column to the database, and editted the order class to record the value. We now need to get the input and pass it to the order class.

All you need to do now is work out how to display the extra information where you need it. If you want it on the orders page in the admin, then you will need to edit admin/orders.php as a starter.

Good luck and hope it helps

Absolute
PS - I have used this before, but just to let you know its not a direct copy and paste, so I may have missed a ';' or two. If you have any issues, let me know

hey there, right iv copied the steps up to the end of "order class"
the box i required is now showing on the "checkout_payment" page
but it is not showing on the order confirmation.....how do i get this data to be sent to me via the email....

also, how do i make it so that this field HAS to be filled to complete the order?

i may not know how yet, but i soon will....i hope :)

20 Jan 2011, 10:10 AM
#72
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Adding Field to Checkout

ok well iv set it up exactly as mentioned, but i still cant seem to get it to show on the order confirmation page or the email

PLEASE HELP MEEEEE!!!

i may not know how yet, but i soon will....i hope :)

20 Jan 2011, 11:17 AM
#73
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Adding Field to Checkout

eddyboy:

Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou
:clap:

My way did seem to work, but I dont trust my coding on 0 sleep..
i have used the new code and it works perfectly

tried using this to make the field REQUIRED

if (isset($_POST['frequent_code']) && !zen_not_null($_POST['frequent_code'])) {  //perform ALL checks on relevancy here
    $messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
    zen_redirect(zen_href_link($_GET['main_page']));
  }
if (zen_not_null($_POST['frequent_code'])) {
$_SESSION['frequent_code'] = zen_db_prepare_input($_POST['frequent_code']);
}
$frequent_code = $_SESSION['frequent_code'];

please tell me if this is wrong??
because it dont seem to make the field required :S

i may not know how yet, but i soon will....i hope :)

20 Jan 2011, 1:19 PM
#74
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding Field to Checkout

It's really very hard to advise you as to what you've missed, without actually seeing the code, but things to check are that you have changed all the "frequent_code" references to the name of the variable you are actually using.

With the order confirmation page, you will need to add this variable to the header_php.php file, or the template file, where the order is looked up within the database.

And finally, within the Order class, you'll find the send email function, where the body of the email is built. You'll need to either tack this varialbe onto the end of the message body, or create a new tag within the email template, and then assign the varialbe to the HTML_MSG array as required.

Good luck,
Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

20 Jan 2011, 4:07 PM
#75
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute:

It's really very hard to advise you as to what you've missed, without actually seeing the code, but things to check are that you have changed all the "frequent_code" references to the name of the variable you are actually using.

With the order confirmation page, you will need to add this variable to the header_php.php file, or the template file, where the order is looked up within the database.

And finally, within the Order class, you'll find the send email function, where the body of the email is built. You'll need to either tack this varialbe onto the end of the message body, or create a new tag within the email template, and then assign the varialbe to the HTML_MSG array as required.

Good luck,
Absolute
lol that confused me :D

  1. Yeah im using frequent_code as my reference

  2. which variable to the header_php.php??

  3. again which variable lol.

complete noob with php :(

i may not know how yet, but i soon will....i hope :)

21 Jan 2011, 9:40 AM
#76
cpannek avatar

cpannek

New Zenner

Join Date:
Sep 2010
Posts:
4
Plugin Contributions:
0

Re: Adding Field to Checkout

Okay, so I've been struggling to get my added fields to post into my data base. I've tried a bunch of different things with this entire post and nothing... before I post my code this is what I'm trying to accomplish:

Need to add 4 fields onto the checkout payment page to take in customer specific information for their order, in my case it's flight information.

Now, heres exactly what I've done following the original instructions provided:

If its the payment page, then edit tpl_checkout_payment_default.php in the same folder. Here you just need to add the field.

The field needs to be as follows:

<?php echo zen_draw_input_field('frequent_code'); ?>

My Code on tpl_checkout_payment_default.php

<fieldset>
<legend><?php echo TABLE_HEADING_FLIGHT_INGO; ?></legend>
<div><?php echo TEXT_FLIGHT_INFO;?></div><br />
<?php echo TEXT_FLIGHT_AIRLINE;?><?php echo zen_draw_input_field('flight_airline'); ?><br />
<?php echo TEXT_FLIGHT_NUMBER;?><?php echo zen_draw_input_field('flight_num'); ?><br />
<?php echo TEXT_FLIGHT_ARV;?><?php echo zen_draw_input_field('flight_arv'); ?><?php echo TEXT_FLIGHT_EX_ARV;?><br />
<?php echo TEXT_FLIGHT_DEP;?><?php echo zen_draw_input_field('flight_dep'); ?><?php echo TEXT_FLIGHT_EX_ARV;?>
</div>
</fieldset>

Firstly, you need to add a new column to the orders database table. Use phpmyadmin, and navigate to the table. Add a new column called order_frequent_code.

Added columns to database:
order_flight_airline
order_flight_num
order_flight_arv
order_flight_dep

Next, alter the order.php class file, found in includes/classes/order.php
There are a fair number of bits to add, but bare with me:

Line 43, add order_frequent_code, to the sql statement.

My Code added to order.php

$order_query = "... order_flight_airline, order_flight_num, order_flight_arv, order_flight_dep, ...

Line 114, before 'ip_address' insert the following line:
'frequent_code' => $order->fields['order_frequent_code'],

My Code added

$this->info = array( ...
'flight_airline' => $order->fields['order_flight_airline'],
'flight_num' => $order->fields['order_flight_num'],
'flight_arv' => $order->fields['order_flight_arv'],
'flight_dep' => $order->fields['order_flight_dep'],
'ip_address' => $order->fields['ip_address']);

Line 343, before 'ip_address' insert the following line:
'frequent_code' => $_SESSION['frequent_code'],

My Code added

$this->info = array( ...
'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
'flight_airline' => $_SESSION['flight_airline'],
'flight_num' => $_SESSION['flight_num'],
'flight_arv' => $_SESSION['flight_arv'],
'flight_dep' => $_SESSION['flight_dep'],
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);

Line 587, before 'ip_address', insert the following line:
'order_frequent_code' => $this->info['frequent_code'],

My Code added

$sql_data_array = array( ...
'order_flight_airline' => $this->info['flight_airline'],
'order_flight_num' => $this->info['flight_num'],
'order_flight_arv' => $this->info['flight_arv'],
'order_flight_dep' => $this->info['flight_dep'],
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);

We now need to get the input and pass it to the order class.

If you placed the new field in the shipping page, then you need to edit includes/modules/pages/checkout_shipping/header_php.php

After line 116 add:
if (isset($_SESSION['frequent_code'])) {
$frequent_code = $_SESSION['frequent_code'];
}

My Code added on includes/modules/pages/checkout_payment/header_php.php

require(DIR_WS_CLASSES . 'order.php');
$order = new order;

if (isset($_SESSION['flight_airline'])) {
$flight_airline = $_SESSION['flight_airline'];
}
if (isset($_SESSION['flight_num'])) {
$flight_num = $_SESSION['flight_num'];
}
if (isset($_SESSION['flight_arv'])) {
$flight_arv = $_SESSION['flight_arv'];
}
if (isset($_SESSION['flight_dep'])) {
$flight_dep = $_SESSION['flight_dep'];
}

After line 124, which starts $comments = $_SESS........ add

if (zen_not_null($_POST['frequent_code'])) {
$_SESSION['frequent_code'] = zen_db_prepare_input($_POST['frequent_code']);
}
$frequent_code = $_SESSION['frequent_code'];

My Code added

//  $_SESSION['comments'] = '';
$comments = $_SESSION['comments'];

if (zen_not_null($_POST['flight_airline'])) {
$_SESSION['flight_airline'] = zen_db_prepare_input($_POST['flight_airline']);
}
$flight_airline = $_SESSION['flight_airline'];

if (zen_not_null($_POST['flight_num'])) {
$_SESSION['flight_num'] = zen_db_prepare_input($_POST['flight_num']);
}
$flight_num = $_SESSION['flight_num'];

if (zen_not_null($_POST['flight_arv'])) {
$_SESSION['flight_arv'] = zen_db_prepare_input($_POST['flight_arv']);
}
$flight_arv = $_SESSION['flight_arv'];

if (zen_not_null($_POST['flight_dep'])) {
$_SESSION['flight_dep'] = zen_db_prepare_input($_POST['flight_dep']);
}
$flight_dep = $_SESSION['flight_dep'];

$total_weight = $_SESSION['cart']->show_weight();
$total_count = $_SESSION['cart']->count_contents();

// load all enabled payment modules
require(DIR_WS_CLASSES . 'payment.php');
$payment_modules = new payment;
$flagOnSubmit = sizeof($payment_modules->selection());

So, I have done all that those instructions stated and it wont populate in my database. I've tried tweaking a few things, but nothing seems to be working... :frusty:

Please help! :cry:

9 Mar 2011, 9:35 AM
#77
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Adding Field to Checkout

hi there
iv managed to get it to show on the orders etc(not the emails yet)

but im just wondering, how do i make it so that the "last" entry put into that box by the customer is forgotten...asin goes to that page and the box is blank again....

thanks in advance

i may not know how yet, but i soon will....i hope :)

15 Feb 2012, 8:11 PM
#78
earlygrayte avatar

earlygrayte

New Zenner

Join Date:
Feb 2012
Posts:
4
Plugin Contributions:
0

Re: Adding Field to Checkout

how did you make it work?
I am really trying my best and can't figure a way to make the form submit data to db. It probably has to do with the fact that I have 1.5 zen cart?
Also how can I name it on the checkout page? I only see the field.
Sorry for noob questions.

27 Feb 2014, 8:37 AM
#79
xav2 avatar

xav2

New Zenner

Join Date:
Jun 2013
Posts:
47
Plugin Contributions:
0

Re: Adding Field to Checkout

the code below only works on checkout_shipping, i get the $my_code value written to database when an order completed
but when i tried the same code to checkout_confirmation, nothing written to database
any ideas?

i'm using zen cart 1.51

<?php 

//File checkout_shipping/header_php.php
if (isset($_SESSION['my_code'])) {
$my_code = $_SESSION['my_code'];
}
if (zen_not_null($_POST['my_code'])) {
$_SESSION['my_code'] = zen_db_prepare_input($_POST['my_code']);
}
$my_code = $_SESSION['my_code'];


//File tpl_checkout_shipping_default.php
$my_code = something;
echo zen_draw_input_field('my_code', $my_code, $parameters = 'readonly', $type = 'text');

?>
28 Feb 2014, 4:41 AM
#80
xav2 avatar

xav2

New Zenner

Join Date:
Jun 2013
Posts:
47
Plugin Contributions:
0

Re: Adding Field to Checkout

the same code works on checkout_shipping and checkout_payment page
but it doesn't work on checkout_confirmation page
what do i use it for checkout confirmation?

xav2:

the code below only works on checkout_shipping, i get the $my_code value written to database when an order completed
but when i tried the same code to checkout_confirmation, nothing written to database
any ideas?

i'm using zen cart 1.51

<?php //File checkout_shipping/header_php.php if (isset($_SESSION['my_code'])) { $my_code = $_SESSION['my_code']; } if (zen_not_null($_POST['my_code'])) { $_SESSION['my_code'] = zen_db_prepare_input($_POST['my_code']); } $my_code = $_SESSION['my_code']; //File tpl_checkout_shipping_default.php $my_code = something; echo zen_draw_input_field('my_code', $my_code, $parameters = 'readonly', $type = 'text'); ?>