Zen Cart Logo
Forums / General Questions / I would like to add one more question to checkout process.

I would like to add one more question to checkout process.

Views: 2,120

Results 1 to 18 of 18
30 May 2012, 7:06 PM
#1
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

I would like to add one more question to checkout process.

Hi! I would like to add one more section to the checkout process for a person to choose a delivery time. I'll present the user with a bunch of options and they need to choose one. Is there a way I can make this part of the checkout process and have their response included in the invoice and the emails that are after after checkout?

Thanks,
BP

31 May 2012, 6:38 AM
#2
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

I would like to add some text to the "comments" field upon checkout. I'm writing my own PHP so that I can manage a delivery option. What I'd like to do is "write" the details of the delivery option in the comment field upon checkout so that when someone looks at the invoice, they'll see the details written.

Here's the tricky part.

I don't want the text to actually show in the comment input box. I don't want the user to have the ability to change the text. What I want to do is, upon checkout, have the delivery information "append" itself to the start of the comment. I have all the delivery information stored as a string variable.

I want the comment in the invoice to look something like this:

DELIVERY INFORMATION

Actual user comment. Please don't break my merchandise.

Any idea how to do this? Was I clear in my explanation?

Thanks,
BP

31 May 2012, 6:40 AM
#3
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

When the user submits an order, the order data gets written into the database. Where is the actual code for this? Where can I find the INSERT INTO query? I'm interested in modifying it. :)

Thanks,
BP

31 May 2012, 7:07 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I would like to add one more question to checkout process.

Answer to all three:

order.php class file:```
$customer_notification = (SEND_EMAILS == 'true') ? '1' : '0';
$sql_data_array = array('orders_id' => $insert_id,
'orders_status_id' => $this->info['order_status'],
'date_added' => 'now()',
'customer_notified' => $customer_notification,
'comments' => $this->info['comments']);

zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);

$this->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_COMMENT', $sql_data_array);
Suggest you use an observer hooked to the NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_COMMENT notifier point instead of editing that file directly.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

31 May 2012, 2:09 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: I would like to add one more question to checkout process.

It appears that that notifier occurs just after the data is written to the database, which would require the observer to then re-edit the db. Wouldn't it be better to modify $this->info['comments'] somewhere before the snippet posted?

The comments field is populated here in the cart() method

    $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
                        'currency' => $_SESSION['currency'],
//...
                        'tax_groups' => array(),
                        'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
``` so I would think (aside from modifying this line) hooking a notifier just after the cart method runs would be best. Not sure where that would be; there doesn't appear to be a notifier to use in the cart() method.
31 May 2012, 6:48 PM
#6
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

If I can find a way to modify the postdata before the variable is passed to the checkout success page, that could answer my question. It may be simple. I'm not sure where to do that, though. I'm still looking at the code.

1 Jun 2012, 3:59 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I would like to add one more question to checkout process.

I guess I'm misunderstanding your intentions here.

Why are you needing to change the existing functionality?
What's wrong with simply inserting an ADDITIONAL orders-status-history entry, so that it shows up as a comment in the order?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Jun 2012, 7:14 AM
#8
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

Ok, now I'm getting more confused. Sorry, please stay with me on this. :)

I have placed this string data as a SESSION variable that will successfully be available upon checkout. I suppose what I'm asking is how exactly would I append this string to the comments upon checkout? I played around with this in the order.php file, but it kept adding the data every time I was on a checkout page. I'm sure I did something wrong.

What I want to do is just have it add to the comment when I check out. Though my PHP and MySQL is adequate, my Zen Cart skills need improvement. I'm slowly learning the back end of the system. What exactly do I need to do?

Dr. Byte and gjh42, I like what you're suggesting, but I'm not sure how to do it. I don't think I completely understand the solution.

Thanks.

1 Jun 2012, 7:20 AM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I would like to add one more question to checkout process.

What exactly is this hard-coded text that you want stuffed into the comment? What does it say and why?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Jun 2012, 7:55 PM
#10
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

It's delivery info. I made a page that allows users to choose a delivery time. Now what I need to do is have this write to the invoice somehow. My method was to store the data as a session and then just stick it in the comments section.

1 Jun 2012, 8:09 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I would like to add one more question to checkout process.

Is there a particular reason why this needs to be the FIRST comment in the order, instead of being an additional comment?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Jun 2012, 10:22 PM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: I would like to add one more question to checkout process.

Not to derail this train of thought, but if you can successfully create a new session variable, could you not instead concatenate its value to the $_SESSION['comments'] variable just before the processing goes off to order.php? It seems that this is the effect you want, that the delivery info is part of the comments.

2 Jun 2012, 6:08 AM
#13
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

gjh42:

Not to derail this train of thought, but if you can successfully create a new session variable, could you not instead concatenate its value to the $_SESSION['comments'] variable just before the processing goes off to order.php? It seems that this is the effect you want, that the delivery info is part of the comments.

Yes, that's my plan. The only thing is that I'm not quite sure where this processing takes place. I tried doing this on the order.php page, and it added the comment every time I changed the page on the checkout screen. What I wanted was to add it once, and that's upon checkout success. Where would I be able to do this?

Again, I'm fine with PHP and MySQL, but this area of Zen Cart is new to me.

And no, it does not need to be the first detail, but I figured it's just as easy to put it at the front as it is the end.

Thanks for the help so far.

2 Jun 2012, 3:30 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: I would like to add one more question to checkout process.

Two options:

a) edit core code by adding your extra variable's content to the existing $_SESSION[comment] value before inserting. Simply do your append or prepend in the same block of code I mentioned earlier.

b) add an observer class that watches for the specified notifier point and have it repeat the same code that I quoted, but putting your custom variable in place of the $_SESSION['comment'] variable. This would add a second entry, basically like a status-update comment. The info will show in the order details screen like other comments do.
While you could technically just duplicate that block of code in the order class file to accomplish the same thing, that requires you to re-do that same edit everytime you upgrade or otherwise touch that file. Using an observer class puts your custom code outside the core code, making it much easier to do upgrades.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

3 Jun 2012, 12:57 AM
#15
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

DrByte:

a) edit core code by adding your extra variable's content to the existing $_SESSION[comment] value before inserting. Simply do your append or prepend in the same block of code I mentioned earlier.

Yes, I suppose I'll go with option A, at least for now. I can do B later.

This is what I've been trying to do. The only problem is... how? I'm playing around with that code block trying to get it to work right.

4 Jun 2012, 6:48 AM
#16
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

Ok, I've added a piece of text to the array:

'comments' => (isset($_SESSION['comments']) ? "HELLO".$_SESSION['comments'] : ''),

It's still a little 'slapped together', but it should do for now. All I need to do is replace the "HELLO" with my session information.

4 Jun 2012, 7:17 AM
#17
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: I would like to add one more question to checkout process.

'comments' => (isset($_SESSION['comments']) ? "HELLO".$_SESSION['comments'] : ''),

Actually, you will want to insert your info whether or not $_SESSION['comments'] is set. You would need to rework that to always populate the 'comments' with your info, and add $_SESSION['comments'] if it exists. Something like ```php
'comments' => "HELLO".(isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),

5 Jun 2012, 2:27 AM
#18
bparker avatar

bparker

Zen Follower

Join Date:
Oct 2008
Location:
Rochester, NY
Posts:
232
Plugin Contributions:
0

Re: I would like to add one more question to checkout process.

gjh42:

Actually, you will want to insert your info whether or not $_SESSION['comments'] is set.

True! And I caught that after I sent it. I've modified my code and everything seems to be working now. Wow, that was a project. :) I mean, passing the variable wasn't a big deal, but everything I had to do to GET the variable was a feat. Had to make a little app.