So you need to know some extra info about your customers? This tutorial will explain how to add extra text fields to Customer Details. I will be using the example of HEIGHT, but this can be changed to any piece of info you need to know.
You will have to edit the following FIVE files:
catalog/create_account.php
catalog/account_edit.php
catalog/includes/languages/english.php
catalog/admin/customers.php
catalog/admin/includes/languages/english.php
So basically you add fields and commands to write to the database in the files, and add the text label (Height, Weight, etc.) in the language files. You have to do the account_edit so your customers can ... edit their account
But first you will need to add a new field to the database in phpMyAdmin. Click on customers, scroll down to the bottom and look for "Add New Field". Add 1 field At End of Table. Enter "height" into the Field name, make sure VARCHAR is selected, and make the Length 3 (this could be any lenth, the default is 32 in oSc, but for my purposes height rarely exceeds 999cms
Now, here we go to the hard part:
1. Open up catalog/includes/languages/english.php
Add your category and your label text. For this example I will be making a category called Sizing, with one entry called Height:
define('CATEGORY_SIZE', 'Sizing');
define('ENTRY_CUSTOMER_HEIGHT','Height');
Now, I wanted to put a little centimeters beside the field so people knew what kind of measure ments to put in. So I added another define:
define('ENTRY_CENTIMETERS_TEXT', 'centimeters');
This can be ANY text you want.
SAVE
2. Open up catalog/create_account.php
What I did here was copy and paste an entire CATEGORY. If you are looking in Dreamweaver, go to around line 500 until you see <?php echo CATEGORY_CONTACT; ?>. Now copy this cell, the one above it (tep_draw_seperator), and the cell below it which contains a table that has telephone and fax info. Then paste these three cells where you want your category to appear.
Select the <?php echo CATEGORY_CONTACT; ?> and change it to <?php echo CATEGORY_SIZE; ?>
Then go one cell down and get rid of the Telephone cells. Select the <?php echo ENTRY_FAX_NUMBER; ?> and change it to <?php echo ENTRY_CUSTOMER_HEIGHT; ?> There is your label done.
The next php block is for drawing the actual form field. Change:
<?php echo tep_draw_input_field('fax') . ' ' . (tep_not_null(ENTRY_FAX_NUMBER_TEXT) ? '<span class="inputRequirement">' . ENTRY_FAX_NUMBER_TEXT . '</span>': ''); ?>
<?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>': ''); ?>
So now the actual form is done. Notice that I have put a character maxlength and a style width on the field? Adjust these as you wish. Also, notice that our centimeters text is going to fall in there real nice. See the special CSS style I gave the centimeter text so it would look nice?
So that is the table are done, but we are going to have to make two more additions.
We are going to need to make a variable, so insert the following around LINE 45:
$height = tep_db_prepare_input($HTTP_POST_VARS['height']);Next search for
$sql_data_array = array('customers_firstname' => $firstname,
Add in 'customers_height' => $height,somewhere in the array. There are TWO arrays, make sure that this is changed in only the first one.
Now whatever is written in the field will be entered into the database.
SAVE
3.Open up catalog/account_edit.php
Here we are going to pull the same trick as above and copy the "My Details" CATEGORY, then edit it to our needs. On line 185 you will see <?php echo MY_ACCOUNT_TITLE; ?>, so basically copy that cell, the one above and the one below. It is from about LINE 174 to LINE 243 in total. Then paste it in below. Again, delete all the unnecessary blocks except for the fax number. Select the <?php echo ENTRY_FAX_NUMBER; ?> and change it to <?php echo ENTRY_CUSTOMER_HEIGHT; ?>. Label finished, now for the field.
Replace:
<?php echo tep_draw_input_field('fax', $account['customers_fax']) . ' ' . (tep_not_null(ENTRY_FAX_NUMBER_TEXT) ? '<span class="inputRequirement">' . ENTRY_FAX_NUMBER_TEXT . '</span>': ''); ?>
with<?php echo tep_draw_input_field('height', $account ['customers_height'],'maxlength="3"' . 'style="width: 50"') . ' ' . (tep_not_null(ENTRY_CENTIMETERS_TEXT) ? '<span class="caption">' . ENTRY_CENTIMETERS_TEXT . '</span>': ''); ?>
There is your table done. Notice that the input field is retrieving info from the database?
Now to make it writable. Add in your variable around LINE 30:
$height = tep_db_prepare_input($HTTP_POST_VARS['height']);
Search for
$sql_data_array = array('customers_firstname' => $firstname, and add in
'customers_height' => $height,somewhere in the array. Make sure to do this only to the TOP one.
Next, search for
$account_query = tep_db_queryYou will have to enter your database field name in here too, so it knows where to look to retrieve the customers data. Here is an example of what MY query looks like:
$account_query = tep_db_query("select customers_gender, customers_firstname, customers_lastname, customers_dob, customers_email_address, customers_height, customers_telephone, customers_fax from "
All done. Now the customer will be able to view their information in My Account, and update the values if they grow a few cms.
SAVE
4. Open up catalog/admin/includes/languages/english.php
Okay, this one is easy. You just do here exactly what you did in step one and add these three chunks:
define('CATEGORY_SIZE', 'Sizing');
define('ENTRY_CUSTOMER_HEIGHT','Height');
define('ENTRY_CENTIMETERS_TEXT', 'centimeters');
SAVE
5. Open up catalog/admin/customers.php
This one gets a little tricky. We are going to copy and paste the Contact CATEGORY, just like what we did to the files over in the catalog. Then rename <?php echo ENTRY_FAX_NUMBER; ?> to <?php echo ENTRY_CUSTOMER_HEIGHT; ?>.
Now, the field is a little tricky. Replace:
<?php
if ($processed == true) {
echo $cInfo->customers_fax . tep_draw_hidden_field('customers_fax');
} else {
echo tep_draw_input_field('customers_fax', $cInfo->customers_fax, 'maxlength="32"');
}
?>
with
<?php
if ($processed == true) {
echo $cInfo->customers_height . tep_draw_hidden_field('customers_height');
} else {
echo tep_draw_input_field('customers_height', $cInfo->customers_height, 'maxlength="3"' . 'style="width: 50"');
}
?>
A little different than what we have done before. Notice the maxlength and the style width.
You will also notice the cInfo, don't worry I don't know what this is for either. Hafta consult a php guy.
One thing we are missing though is the cms after the field. This is simply because I haven't figured out how to get that text in there. Once again, we'll have to consult a PHP guy.
In any case, the table is set up, now we have to do our database stuff again, so insert our variable at around LINE 30
$customers_height = tep_db_prepare_input($HTTP_POST_VARS[ 'customers_height']);
Search for:
$sql_data_array = array('customers_firstname' => $customers_firstname,
and enter in below:
'customers_height' => $customers_height,
Remember to do this only on the top sql query.
Find the $customers_query and enter in c.customers_height. Notice the difference from step 3. Here is an example of what MY query looks like:
$customers_query = tep_db_query("select c.customers_id, c.customers_gender, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, c.customers_height, a.entry_company, a.entry_street_address, a.entry_suburb, a.entry_postcode, a.entry_city, a.entry_state, a.entry_zone_id, a.entry_country_id, c.customers_telephone, c.customers_fax, c.customers_newsletter, c.customers_default_address_id from "
Now we are DONE!!!
SAVE!!!!
Adjust at will, put those 5 files on the server and give it a go. All should be fine.
Good luck!!
Edited by Rusyn, 18 May 2004 - 01:51 AM.









