Zen Cart Logo
Forums / General Questions / Adding extra fields to admin copy of order confirmation email, and orders area.

Adding extra fields to admin copy of order confirmation email, and orders area.

Views: 4,468

Results 1 to 20 of 30
10 Mar 2013, 10:28 PM
#1
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Adding extra fields to admin copy of order confirmation email, and orders area.

I have added an add-on module that allows me to add custom fields to the customer during signup. I really need these fields sent to the Admin order confirmation e-mail if possible. And once past this step perhaps I can also have these data fields show up on the shipping address of the orders area.

First my greatest need is to have the extra data fields added to my order confirmation e-mails. I have read this post: but for some reason I am just not getting it. My extra fields are labeled as: extrafield, extrafield2, extrafield3

I am assuming I need to add definitions to the: includes/classes/order.php. I would like the: extrafield2 and extrafield3 to show up right under the persons name, and the extrafield to show up on top of the shipping address. I would also like to have the label and the answer (i.e. etrafield2 would be: Chapter Letters, and their answer might look like: AN. It would be nice to show question and answer together).

So this is what I have added to my order.php file:
Line #936

Original Code:

    // lets start with the email confirmation
    // make an array to store the html version
    $html_msg=array();

    //intro area
    $email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
    $this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
    EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
    EMAIL_SEPARATOR . "\n"

Modified Code:

    // lets start with the email confirmation
    // make an array to store the html version
    $html_msg=array();

    //intro area
    $email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
    $this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
    $this->customer['extrafield2']. "\n\n" .
    $this->customer['extrafield3']. "\n\n" .
    EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
    EMAIL_SEPARATOR . "\n" 

For the billing address area where I would like the lone extrafield to show I have this (Around line #987):

Original Code:

//addresses area: Delivery
    $html_msg['HEADING_ADDRESS_INFORMATION']= HEADING_ADDRESS_INFORMATION;
    $html_msg['ADDRESS_DELIVERY_TITLE']     = EMAIL_TEXT_DELIVERY_ADDRESS;

Modified Code:

//addresses area: Delivery
    $this->customer['extrafield']. "\n\n" .
    $html_msg['HEADING_ADDRESS_INFORMATION']= HEADING_ADDRESS_INFORMATION;
    $html_msg['ADDRESS_DELIVERY_TITLE']     = EMAIL_TEXT_DELIVERY_ADDRESS;

During testing the first example with extrafield2 and extrafield3 displayed blank results (there were blank spaces where the data would show) and the second example just did not show at all (no spaces nothing).

Obviously for a PHP coder would see the issue, but I just do not know PHP hence my poor writing skills above. Anyone?

10 Mar 2013, 10:45 PM
#2
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Sorry forgot to post the defines for my custom files according to the language file is:
ENTRY_EXTRAFIELD, ENTRY_EXTRAFIELD2, and ENTRY_EXTRAFIELD3

11 Mar 2013, 10:08 PM
#3
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Hmmmmm. No feedback yet?

12 Mar 2013, 2:16 PM
#4
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

You will need to first read the extra fields in from the database before you can add them to the email. The customer's ID is usually in $_SESSION['customer_id'] during the checkout process.

12 Mar 2013, 4:36 PM
#5
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

lhungil:

You will need to first read the extra fields in from the database before you can add them to the email. The customer's ID is usually in $_SESSION['customer_id'] during the checkout process.

OK. Please bare with me as I am not sure what I am doing here. Within this add-on file I am using, I have the database install.sql file. For one of my extra fields I see this:

ALTER TABLE customers ADD customers_extrafield2 varchar(32) NOT NULL AFTER customers_extrafield;

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Display Extra Field #2', 'DISPLAY_EXTRAFIELD2', 'true', 'Display Extra Field #2 on Sign Up page and My Account page', '5', '6', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now());

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Require Extra Field #2', 'EXTRAFIELD_REQUIRED2', 'true', 'Require Extra Field #2 on Sign Up page and My Account page', '5', '7', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now());

My best guess would be this: customers_extrafield2 taken above would be the database identified I need?

If so then this:
$_SESSION['customers_extrafiled2'] would be needed to call it from the database. And if this is the case, then how would I add this to the PHP code example above.

So instead of:
$this->customer['extrafield2']. "\n\n" .
Use this:
$_SESSION['customers_extrafiled2']
$this->customer['extrafield2']. "\n\n" .

12 Mar 2013, 5:50 PM
#6
david_allen avatar

david_allen

Zen Follower

Join Date:
Feb 2008
Location:
Amersham, Buckinghamshire, United Kingdom
Posts:
141
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

sports guy:

OK. Please bare with me as I am not sure what I am doing here.

No problem

What lhungil was saying is that you will need to use the $_SESSION['customers_id'] in an sql query to extract the info from the database

Something like:

global $db;
$extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customers_id']

$extra_fields = $db->Execute($extra_query);

then you can use $extra_fields->fields['extrafields1'] as the value for extrafield1 - and similarly for extrafield2 and 3

Hope this helps

17 Mar 2013, 12:51 AM
#7
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

David Allen:

Something like:

global $db;
$extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customers_id']

$extra_fields = $db->Execute($extra_query);

> then you can use $extra_fields->fields['extrafields1'] as the value for extrafield1 -  and similarly for extrafield2 and 3
> 
> Hope this helps

I added this code to my orders.php as you recommended:

global $db;
$extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customers_id']
$extra_fields = $db->Execute($extra_query);


This code produced a red error line in Dreamweaver (line #3) brought up a syntax error. Then when I was testing during checkout I got a this error:
"WARNING: An Error occurred, please refresh the page and try again." and the order confirmation page went blank. Am I missing something here?
17 Mar 2013, 12:53 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Start with adding a semi-colon on the end of:

$extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customers_id'][B];[/B]
17 Mar 2013, 1:21 AM
#9
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

OK Ajeh,
The semi-colon did remove the syntax error in Dreamweaver. However I still get the blank order confirmation page that says: "WARNING: An Error occurred, please refresh the page and try again." So I guess there is not a syntax error, but a problem with the definitions themselves?

17 Mar 2013, 1:36 AM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Change:
$_SESSION['customers_id']

to be:
$_SESSION['customer_id']

17 Mar 2013, 1:53 AM
#11
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

OK I did that. This is the code I have:

global $db;
    $extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customer_id'];
    $extra_fields = $db->Execute($extra_query);
    $extra_fields->fields['extrafields1'];

I still get the blank page error. If I remove the coding above completely it checks out fine.

17 Mar 2013, 2:12 AM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

This line is just hanging out there ... you need to do something with it :

    $extra_fields->fields['extrafields1'];
17 Mar 2013, 2:25 AM
#13
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

OK. In different areas of my Extra Fields module I have found these definitions (So I am using this to try and determine the correct definitions I need):

$account->fields['customers_firstname'], 'id="firstname"')
$account->fields['customers_extrafield'], 'id="extrafield"')
$account->fields['customers_extrafield2'], 'id="extrafield2"')

$firstname = zen_db_prepare_input($_POST['firstname']);
$extrafield = zen_db_prepare_input($_POST['extrafield']);
$extrafield2 = zen_db_prepare_input($_POST['extrafield2']);

array('fieldName'=>'customers_firstname', 'value'=>$firstname, 'type'=>'string'),
array('fieldName'=>'customers_extrafield', 'value'=>$extrafield, 'type'=>'string'),
array('fieldName'=>'customers_extrafield2', 'value'=>$extrafield2, 'type'=>'string'),

First, notice all the fields above are singular: extrafield instead of extrafields, except for 1? So I thought this would be more appropriate:

global $db;
    $extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customer_id'];
    $extra_field = $db->Execute($extra_query);     
    $extra_field->fields['extrafield1'];

You say this line: $extra_field->fields['extrafield1']; is just hanging out there. I thought what David Allen was telling me, was this line would then display (call up) the extra field into the e-mail. So this line is supposed to show what the other lines are calling up? If not, is that line just useless, just delete and get rid of?

17 Mar 2013, 2:28 AM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

That should be fields ...

However you just have that "field" sitting there not doing anything like:

echo $extra_field->fields['extrafield1'];

Just having:

    $extra_field->fields['extrafield1'];

on a line means nothing and is confusing the code ...

17 Mar 2013, 2:47 AM
#15
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

OK I get that. So by saying echo, we are calling the code to display the text. Now this is my coding:

global $db;
    $extra_query ='Select extrafield1, extrafield2, extrafield3 from '.TABLE_CUSTOMERS.' where customers_id = '.$_SESSION['customer_id'];
    $extra_field = $db->Execute($extra_query);
    echo $extra_field->fields['extrafield1'];

I just don't know what I am doing here. I am not sure if I need to enter my variables from the plug-in. The code above is still pulling a blank page with an error so something is wrong.

17 Mar 2013, 2:50 AM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

What do you see in your debug logs?

17 Mar 2013, 2:58 AM
#17
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Try this:

global $db;
    $extra_query ="SELECT extrafield1, extrafield2, extrafield3 from ".TABLE_CUSTOMERS." WHERE customers_id = '".$_SESSION['customer_id'] ."'";
    $extra_field = $db->Execute($extra_query);
    echo 'I SEE: ' . $extra_field->fields['customers_id'];

This handles when there isn't a $_SESSION['customer_id']

17 Mar 2013, 3:17 AM
#18
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

This was in my error log:

[16-Mar-2013 21:56:25] PHP Fatal error: 1054:Unknown column 'extrafield1' in 'field list' :: Select extrafield1, extrafield2, extrafield3 from customers where customers_id = 1 in /home/peoyear/public_html/includes/classes/db/mysql/query_factory.php on line 120

I did change to your suggestion above and the same thing. Since the above error says this: 'extrafield1' is unknown in the field list and I see this code: "$account->fields['customers_extrafield'], 'id="extrafield"')" in another area of the module, should I try and change extrafield1 to customers_extrafield?

Maybe something like this:

echo $extra_field->fields['customer_extrafield'];

Also shouldn't this: Select extrafield1, extrafield2, extrafield3 be: Select customer_extrafield, customer_extrafield2, customer_extrafield3? I am seeing customers_extrafield, customers_extrafield2, customers_extrafield3 in the database under customers!

17 Mar 2013, 3:21 AM
#19
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Ohhh. While in the database (phpMyAdmin) the correct definition for customer id is plural: customers_id

17 Mar 2013, 10:07 AM
#20
david_allen avatar

david_allen

Zen Follower

Join Date:
Feb 2008
Location:
Amersham, Buckinghamshire, United Kingdom
Posts:
141
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Ajeh:

Change:
$_SESSION['customers_id']

to be:
$_SESSION['customer_id']

Oops - soory for the typos - well caught Linda.
Regards