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

Adding Field to Checkout

Results 1 to 20 of 84
02 Sep 2006, 20:17
#1
paperzombie avatar

paperzombie

Zen Follower

Join Date:
Aug 2006
Posts:
100
Plugin Contributions:
0

Adding Field to Checkout

I searched for this and only came up with one thread which was what I was looking for, but they figured out another way of doing it..

I need to know if there is a way to add a field to the checkout. I send out frequent buyer cards to buyers, potential customers and for others to pass out too, so theres no way of me tracking WHO has a frequent buyer card so i want a frield in the check out just to ask if they have a frequent buyer card, so that if they dont, i can send them one. Is there anyway of doing this?
02 Sep 2006, 22:28
#2
absolute avatar

absolute

Totally Zenned

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

Re: Adding Field to Checkout

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.

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'];
}
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'];

And that should be it!

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
03 Sep 2006, 11:26
#3
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Adding Field to Checkout

A very good, very comprehensive, very accurate and very clear response to one of those "more difficult than it looks" questions. Many thanks for posting it.

I'd just add that since the order.php and the shipping header.php files are outside of the current over-ride system, it may be necessary to reapply the changes when you upgrade. I'd recommend checking the change documentation carefully to see if these files are included in the list of amended files.
06 Sep 2006, 15:38
#4
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Absolute...this was great...unfortunately...it didn't work for me.

Here's my situation-

On this page:

http://www.theemployeemall.com/chs/index.php?main_page=checkout_payment

In the Values in Action certificates section, I need to add (under Certificate Number):

Employee ID
Reward Date
Presenter

Do you think you can modify your instructions for me...so I can get it to work?

Thanks!
06 Sep 2006, 16:28
#5
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Adding Field to Checkout

You are popping your fields onto the checkout payment page for which a small modification to the absolute's instructions would be needed.

Unlike the checkout shipping page which recalls itself when it has finished to validate the input, the checkout payment page skips merrily onto the checkout confirmation page, so your validation and setting of $_SESSION variables needs to take place in the modules/pages/checkout_confirmation/header_php.php (just after line 51 would be appropriate). However, your checking whether they are already set (e.g. for when the user is returmned to the page after failing php-based validation) should be put in modules/pages/checkout_payment/header_php.php (after line 90 say).
06 Sep 2006, 16:52
#6
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Thanks...I tried what you suggested and this is what I come up with:

http://www.theemployeemall.com/chs/index.php?main_page=checkout_payment

In the Values in Action Certificates section I get the three extra boxes I created (not aligned and with no identifier to say what info should go in there).

But, I also get three additional text boxes in the Shopping Passes section. Those shouldn't be there.

Any suggestions?
06 Sep 2006, 18:27
#7
absolute avatar

absolute

Totally Zenned

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

Re: Adding Field to Checkout

Can you post the code for the page you altered? Just the section you editted will be fine, for tpl_checkout_payment_default.php. THen we can take a look at your code, and iron out the issue.

Absolute
06 Sep 2006, 19:14
#8
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

The three field ID's I created are: employeeid, rewarddate, presenter.

Here's the code:

<fieldset>
<legend><?php echo $selection[$i]['module']; ?></legend>
<?php echo $selection[$i]['redeem_instructions']; ?>
<div class="gvBal larger"><?php echo $selection[$i]['checkbox']; ?></div>
<label class="inputLabel"<?php echo ($selection[$i]['fields'][$j]['tag']) ? ' for="'.$selection[$i]['fields'][$j]['tag'].'"': ''; ?>><?php echo $selection[$i]['fields'][$j]['title']; ?></label>
<?php echo $selection[$i]['fields'][$j]['field']; ?>
<?php echo zen_draw_input_field('employeeid'); ?>
<?php echo zen_draw_input_field('rewarddate'); ?>
<?php echo zen_draw_input_field('presenter'); ?>
</fieldset>
06 Sep 2006, 20:53
#9
absolute avatar

absolute

Totally Zenned

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

Re: Adding Field to Checkout

Hey Steve,

You'll notice that the previous line to the ones you posted is:

<?php
}
for ($j=0, $n2=sizeof($selection[$i]['fields']); $j<$n2; $j++) {
?>

This means that the code you have altered is within the FOR loop, which in your case, runs twice.

I would recommend either including a check to ensure $j == 0, or move your code.

If you want to include the test for $j==0, then use.....
if ($j==0) {
YOUR NEW TEXTBOXES HERE
}


Good luck

Absolute
06 Sep 2006, 21:23
#10
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Thanks...being that the boxes are where I need them, I can't move them (well, maybe I can, but that's probably a bigger issue than I need).

So, it sounds like I have to do this "check," unfortunately I'm not exactly sure what I need to do.

You provided code...is that the EXACT code I need to enter, and if so, where does it go?
06 Sep 2006, 23:23
#11
absolute avatar

absolute

Totally Zenned

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

Re: Adding Field to Checkout

Replace the code you posted with this:
<fieldset>
<legend><?php echo $selection[$i]['module']; ?></legend>
<?php echo $selection[$i]['redeem_instructions']; ?>
<div class="gvBal larger"><?php echo $selection[$i]['checkbox']; ?></div>
<label class="inputLabel"<?php echo ($selection[$i]['fields'][$j]['tag']) ? ' for="'.$selection[$i]['fields'][$j]['tag'].'"': ''; ?>><?php echo $selection[$i]['fields'][$j]['title']; ?></label>
<?php 
echo $selection[$i]['fields'][$j]['field'];
if ($j==0) {
echo zen_draw_input_field('employeeid') . zen_draw_input_field('rewarddate') .  zen_draw_input_field('presenter'); 
}
?>
</fieldset>  


Absolute
07 Sep 2006, 00:32
#12
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Posted that code and I still have the three extra boxes.

Also, the three that are in the right spot aren't lined up and no Label.

Thanks for the help...I'm ready for another suggestion.
07 Sep 2006, 01:24
#13
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Adding Field to Checkout

Reading over the thread, I think that there's a crossed wire here.

Absolute is trying to ensure that the block of code that you posted (lines 70-84) only generates one set of your three fields. However, the second set of fields that it seems you don't want, haven't been generated by this block of code at all. They've come from lines 90-182 that deals with payment methods.

Much of the data generated in the payment methods section of the page comes from elsewhere and is merely displayed by this block of code. Have you either edited lines 90-182, edited or created a payment module to create your "Manager Rewards" payment type or installed a 3rd party add-on payment module?
07 Sep 2006, 01:40
#14
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Yes, I have the Purchase Order module.
07 Sep 2006, 16:53
#15
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Solution:

I added the new fields as attribute text boxes (required) in the appropriate products. Problem solved.

Was at wits end when I remembered reading on this forum something similar...stressed out and tired, I remembered it and implemented it!

Thanks to everyone for their assistance.
07 Sep 2006, 16:57
#16
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Posts:
10,475
Plugin Contributions:
9

Re: Adding Field to Checkout

Provided you're happy for it to be required for every product ordered, that's a good solution and much more straightforward than adding it to the checkout.
07 Sep 2006, 17:47
#17
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

It's only one category (about 20 products)...so it's easy to add the attributes and it works!

Thanks for the help.
07 Sep 2006, 17:52
#18
absolute avatar

absolute

Totally Zenned

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

Re: Adding Field to Checkout

You just need to consider whether you want to add it once per order, or 20 times, if the customer orders all 20 products. What do the details refer to - the product or the order?

Sorry to throw the spanner in the works

Absolute
07 Sep 2006, 18:45
#19
stevehare avatar

stevehare

Zen Follower

Join Date:
Dec 2005
Posts:
108
Plugin Contributions:
0

Re: Adding Field to Checkout

Actually, it works out well.

The customer is actually an employee that gets to order one product from that category using a certificate earned through work.

So, they will only have to enter the info once per order (and per certificate).

Again, thanks for the help.
17 Jan 2007, 16:36
#20
ngr avatar

ngr

New Zenner

Join Date:
Dec 2006
Posts:
23
Plugin Contributions:
0

Re: Adding Field to Checkout

how can i show the info inserted in the Admin?. i have super orders so in admin>super orders.php i add these lines, but the info inserted not appear.
<tr>
<td class="main"><strong><?php echo FREQUENT_CODE; ?></strong></td>
<td class="main"><?php echo $order->info['frequent_code']; ?></td>
</tr>

thanks!