Jump to content



Latest News: (loading..)

* * * - - 5 votes

Adding Custom Fields to Customer Details


This topic has been archived. This means that you cannot reply to this topic.
84 replies to this topic

#81   Brooks552

Brooks552
  • Members
  • 55 posts

Posted 11 December 2009 - 03:26 PM

Hi there, for me this contribution has been a lifesaver as I'd been looking to add a number of fields to the customer account for some time however I still can't get the additional information to show in the packingslip or invoice.

I've tried all manner of things and even gone as far as trying to duplicate the new fields in the ORDER table in the db as well as in the CUSTOMER table (but this simply won't write from the checkout_process.php file).

Is there anyway I can do a cross table query (matching customer_id in the customer table and orders table of the db) to pick up the information and present it in the invoice?

If anyone can help with getting the new data into this file it woudl be appreciated.

Thanks

#82   Brooks552

Brooks552
  • Members
  • 55 posts

Posted 11 December 2009 - 03:32 PM

View Posttimmle, on 05 October 2009 - 10:47 PM, said:

After nearly a year i have returned to this thread, seems to be inactive for the past 6 months.

Can anyone, with the same step by step accuracy as the first initial tutorial, please explain how to request the data from the extra fields and put them in the invoice and packing slip, order email etc, basically anything that is sent through with the order on it, needs to have this information.

And also how to have a drop down menu instead of a text input field.


I hope someone can help, just to add extra details to everything sent through from the store, and changing the text input fields to drop down menus.

Tim.

Hi Tim

I don't know if you've found a solution yet but I managed to get a series of drop downs to work by replacing the input field code:

<?php echo tep_draw_input_field('height','','maxlength="3"' . 'style="width: 50"') . ' ' . (tep_not_null(ENTRY_CENTIMETERS_TEXT) ? '<span class="caption">' . ENTRY_CENTIMETERS_TEXT . '</span>': ''); ?>

with the following:

<?php //Rta drop-down
  $Rta_array = array();
$Rta_array[0] = array('id' => '0', 'text' => 'Please Select');
$Rta_array[1] = array('id' => '-900', 'text' => '-900');
$Rta_array[2] = array('id' => '-800', 'text' => '-800');
?>
<td class="main" width="20%" align="center"><?php echo tep_draw_form('Rta', tep_href_link('links.php', 'action=catsel'), 'get').'' . 
tep_draw_pull_down_menu('Rta', $Rta_array, $account ['customers_Rta']); ?></td>

Rather than use a database query to extract the dd options I've hard coded the list content as I found this easier.  The initial code stipulates the data for the dd and the <td> onwards presents the fields in the page.

This seems to work OK for me in conjunction with the rest of the instructions at the beginning of this thread.

#83   jerrico

jerrico
  • Members
  • 2 posts

Posted 22 January 2010 - 04:49 PM

With regards to adding information from custom fields into other things (like the confirmation e-mail or the confirmation page), I also had this problem and found a quick/dirty solution.  I'm not a PHP or database expert by any means, so there are likely more efficient means to do this, but:

1. go to catalog/includes/languages/english/checkout_process.php and add the text that you want to appear in the e-mail to preface your custom field, you can add this anywhere within the code, like:

define('EMAIL_CAMPUS_ADDRESS', 'Campus Address:');

that will insert the words "Campus Address" into the confirmation e-mail when I called EMAIL_CAMPUS_ADDRESS.  You can add whatever you want.

2. go to catalog/includes/checkout_process.php.  The new database entry that I created via the first post in this tutorial is called customers_campus_address.  To get information from the customers part of the database I selectively copied code that I found in other files that call the database.  (This might be duplicitous because there already appears to be code to do this in checkout_process - but it worked for me so others are free to suggest better solutions).  customers_campus_address is my new database entry and variable so replace that with yours in the same manner as the tutorial in this post.  I put my variable as the last entry in these examples where I had to put it in.  Find:

// load the before_process function from the payment modules
  $payment_modules->before_process();

and, after it, insert:

		$customers_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
		$customers_firstname = tep_db_prepare_input($HTTP_POST_VARS['customers_firstname']);
		$customers_lastname = tep_db_prepare_input($HTTP_POST_VARS['customers_lastname']);
		$customers_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']);
		$customers_telephone = tep_db_prepare_input($HTTP_POST_VARS['customers_telephone']);
		$customers_fax = tep_db_prepare_input($HTTP_POST_VARS['customers_fax']);
		$customers_newsletter = tep_db_prepare_input($HTTP_POST_VARS['customers_newsletter']);
		$customers_gender = tep_db_prepare_input($HTTP_POST_VARS['customers_gender']);
		$customers_dob = tep_db_prepare_input($HTTP_POST_VARS['customers_dob']);
		$default_address_id = tep_db_prepare_input($HTTP_POST_VARS['default_address_id']);
		$entry_street_address = tep_db_prepare_input($HTTP_POST_VARS['entry_street_address']);
		$entry_suburb = tep_db_prepare_input($HTTP_POST_VARS['entry_suburb']);
		$entry_postcode = tep_db_prepare_input($HTTP_POST_VARS['entry_postcode']);
		$entry_city = tep_db_prepare_input($HTTP_POST_VARS['entry_city']);
		$entry_country_id = tep_db_prepare_input($HTTP_POST_VARS['entry_country_id']);
		$entry_company = tep_db_prepare_input($HTTP_POST_VARS['entry_company']);
		$entry_state = tep_db_prepare_input($HTTP_POST_VARS['entry_state']);
	$customers_campus_address = tep_db_prepare_input($HTTP_POST_VARS['customers_campus_address']);



		$sql_data_array = array('customers_firstname' => $customers_firstname,
								'customers_lastname' => $customers_lastname,
								'customers_email_address' => $customers_email_address,
								'customers_telephone' => $customers_telephone,
								'customers_fax' => $customers_fax,
								'customers_newsletter' => $customers_newsletter,
								'customers_campus_address' => $customers_campus_address,);

		$sql_data_array = array('entry_firstname' => $customers_firstname,
								'entry_lastname' => $customers_lastname,
								'entry_street_address' => $entry_street_address,
								'entry_postcode' => $entry_postcode,
								'entry_city' => $entry_city,
								'entry_country_id' => $entry_country_id);


  $account_query = tep_db_query("select customers_gender, customers_firstname, customers_lastname, customers_dob, customers_email_address, customers_delivery, customers_telephone, customers_fax, customers_campus_address from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
  $account = tep_db_fetch_array($account_query);

remember wherever I put customers_campus_address just replace that with your variable(s).


3. to actually display what you have, again in the catalog/includes/checkout_process.php file go down to

// lets start with the email confirmation
  $email_order = STORE_NAME . "\n" . 

and, wherever you'd like to position the information that you want to display in the e-mail, call the variable by calling, in my case, $account['customers_campus_address'], so, for example

  $email_order = STORE_NAME . "\n" . 
				 EMAIL_SEPARATOR . "\n" . 
				 EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" .
				 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" .
				 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n" .
				 EMAIL_CAMPUS_ADDRESS . ' ' . $account['customers_campus_address'] . "\n\n";

will print the text that I put into "EMAIL_CAMPUS_ADDRESS" in catalog/includes/languages/english/checkout_process.php and display the information in my database entry (customers_campus_address) right below the "more detailed invoice."  Replace customers_campus_address with whatever variable you have, save and upload the 2 files, and you should be good.  You could also access other variables from that large list (just call whatever other variables you inserted in step 2) in the same manner.  You can follow the code further in this section of the file to get a look at where information is displayed in the e-mail and edit/insert accordingly.  The "\n" will add an extra space at the end of the line, make sure to end the last statement that you have in the block with a ; (semi-colon).  You can also add more information - like if you want to call their telephone number, call $order->customer['telephone'], etc.  

You can also put this on your order confirmation page or elsewhere as you might like.

Hope this helps!

#84   ce55l

ce55l
  • Members
  • 11 posts

Posted 17 July 2011 - 11:55 AM

Many thanks, Very useful post.

#85   zinor

zinor
  • Members
  • 58 posts

Posted 19 July 2011 - 07:12 PM

hello everybody
unfortunately i got a bad problem with this !
i just rename one of my customer text field and change FAX to MOBILE and a new customer can register through my new text fileds successfully and also he can edit them without any problem and all details of customers insert in my mysql data bank successfully but my problem is in the admin area in the customers area where you can see your registered customers ! in that area all customers name and family name are shown but when you click on them you CAN NOT EDIT them ( you dont enter to the page to edit the filed ) and also you CAN NOT DELETE them and all summary fileds in the right place of every customers is empty like last logon last change country and etc  !
i attached you the customers.php of my website .
can anyone help me !?