Jump to content



Photo
* * * - - 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

#1   Rusyn

Rusyn
  • Members
  • 137 posts

Posted 18 May 2004 - 01:49

Adding Custom Fields to Customer Details

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 /wink.gif' class='bbc_emoticon' alt=';)' />, and in case you want to see/change their info in the Admin, you will have to change stuff in their too.

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 /wink.gif' class='bbc_emoticon' alt=';)' />) Hit OKAY and you are done!


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') . '&nbsp;' . (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"') . '&nbsp;' . (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']) . '&nbsp;' . (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"') . '&nbsp;' . (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_query
You 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. /wink.gif' class='bbc_emoticon' alt=';)' />

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.


#2   WS Evolution

WS Evolution
  • Members
  • 192 posts

Posted 25 May 2004 - 10:03

Thanks Rusyn this has been very useful. I have successfully added three new custom fields for a wholesale members only shop. This has probably saved me many hours, searching through the code.

Many thanks, /smile.gif' class='bbc_emoticon' alt=':)' />

#3   WS Evolution

WS Evolution
  • Members
  • 192 posts

Posted 25 May 2004 - 12:30

If you what to add a "text area" this is how to do it.....



In catalog/admin/customers.php



<tr>
                       <td class="main"><?php echo CUSTOMER_COMMENTS; ?></td>
                       <td class="main"><?php echo tep_draw_textarea_field('comments', 'soft', 50, 15, $cInfo->comments); ?></td>
  
               </tr>

In catalog/create_account.php


<tr class="infoBoxContents">

            <td><table border="0" cellspacing="2" cellpadding="2">

              <tr>

                <td class="main"><?php echo CUSTOMER_COMMENTS; ?></td>

                <td class="main"><?php echo  tep_draw_textarea_field('comments', 'soft', 50, 15) . '&nbsp;' . (tep_not_null(CUSTOMER_COMMENTS_TEXT) ? '<span class="inputRequirement"><br>' . CUSTOMER_COMMENTS_TEXT . '</span>': ''); ?></td>

              </tr>

            </table></td>

          </tr>


#4   gal1264

gal1264
  • Members
  • 11 posts

Posted 27 May 2004 - 06:05

Yeah....this worked out GREAT and is really helpful.

#5   nscmonkey

nscmonkey
  • Members
  • 17 posts

Posted 06 July 2004 - 21:19

One note:

Enter "height" into the Field name, make sure VARCHAR is selected, and make the Length 3...

I think this should read:

Enter "customers_height" into the Field name, make sure VARCHAR is selected, and make the Length 3 ...

It's the only way it would work for me.

#6   tcjay

tcjay
  • Members
  • 181 posts

Posted 15 July 2004 - 17:53

They should add this to the knowledge base because it explains exactly the steps needed to add new fields andcreate forms to edit, retreive and save information in the new fields, to the database.
Live free or die

#7   kittidid

kittidid
  • Members
  • 197 posts

Posted 17 July 2004 - 18:03

I just added all the above to add a alt phone field. All went fine. Except now when I create an account, add products to cart, checkout.....I am suppose to be taken to the shipping page first, but it skips over it and goes straight to the payment page. And when I submit the order the shipping address is blank in my emails.

What do I correct to fix this.

Kitti

#8   kittidid

kittidid
  • Members
  • 197 posts

Posted 18 July 2004 - 01:14

Got it! I was missing some code that I was suppose to enter.

Kitti

#9   annuxx

annuxx
  • Members
  • 13 posts

Posted 18 July 2004 - 22:41

Could this also add these fields to the address book by editing /catalog/address_book.php and /catalog/address_book_process.php? Can this be displayed in shipping info?

The shopping cart address book are used by our customers to hold their clients info for rewards and gifts.

E.G. I would add fields DOB, Spending Limit and Occassion to be used by customers to indicate to us how much a gift would cost, when it should be recieved, and for what type of occassion.

Im running to a bit of trouble with my added fields just wondering if your solution would work.

#10   sayguh

sayguh
  • Members
  • 6 posts

Posted 11 August 2004 - 13:23

Hi All,

I have added my custom field successfully..


Is anyone able to tell me how to make a custom field be REQUIRED?

Thanks!
sayguh

#11   kristymichelle

kristymichelle
  • Members
  • 42 posts

Posted 12 August 2004 - 18:51

I have sucessfully added custom fields to my customer information. I have some fields that need to be required. I looked in the form_check.js.php file but I can't figure out how to make it come up with an error if the person doesn't enter anything in.
Also, I am trying to figure out how to add this new information to the invioice. Any one have any sugestions?? Thanks.

#12   mrsC2003

mrsC2003
  • Members
  • 131 posts

Posted 13 August 2004 - 22:56

So what if you want to add something in the admin that is just for you.

Example:

You buy something that cost $15 (your price) and you want to sell it for say $25 (retail price).

You don't want your price to show in the store, but you do want it to show in the admin in the catelog section when you add a product, as well as the selling price.
I live in my own little world. But it's OK. They know me here.

#13   Druide

Druide
  • Members
  • 882 posts

Posted 18 August 2004 - 04:56

So what if you want to add something in the admin that is just for you.

Example:

You buy something that cost $15 (your price) and you want to sell it for say $25 (retail price).

You don't want your price to show in the store, but you do want it to show in the admin in the catelog section when you add a product, as well as the selling price.

you did reply in the wrong thread mrsC2003
Robert

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

#14   mrsC2003

mrsC2003
  • Members
  • 131 posts

Posted 18 August 2004 - 13:38

well since the person was giving a tutorial on add things I though I would ask if they would mind showing us how to do something different....sorry

Kel
I live in my own little world. But it's OK. They know me here.

#15   Destral

Destral
  • Members
  • 2 posts

Posted 08 September 2004 - 02:51

Great tutorial!!!
But....
Now I have a Problem:

How can I make that specific data (height=Client Internal Code) to show on Invoices and Orders follow up??
I've been trying and the text shows quite well the ENTRY_STUFF but the user info doesn't.
I guess I have to retrieve the data from the DB first for it to show... like in the example (customer_stuff$) but I really don't have any idea where or how to do this.

Any help will be very much appreciated /biggrin.gif' class='bbc_emoticon' alt=':D' />

Regards,

Mike

#16   martinmacca

martinmacca
  • Members
  • 107 posts

Posted 02 October 2004 - 14:36

Ive followed this guide to add a 2nd line for the address field. Its writing to the database correctly, but it isnt showing in the customer address summary. In the 1st pic you can see the extra field which works fine when the customer edits their account address, but in the rest of the catalog the field isnt included as in pic 2. Any ideas how to get the new field included in the primary address ?
[img]http://www.custom-pcsystems.com/images/editaccount.jpg[/img]
[img]http://www.custom-pcsystems.com/images/accountaddy.jpg[/img]

#17   martinmacca

martinmacca
  • Members
  • 107 posts

Posted 02 October 2004 - 15:58

sorted /cool.gif' class='bbc_emoticon' alt='B)' />

#18   chardae

chardae
  • Members
  • 73 posts

Posted 03 October 2004 - 04:41

/crying.gif' class='bbc_emoticon' alt=':'(' /> There Are several changes needed to accomplish the task of adding a second address line. These changes include the Admin side. After all if a customer adds additional address information you need that information to process the order properly. For example if the customer uses the second address line to add his/her apartment number, you surely need that information for proper delivery of products.

I have accomplished this task in full on my site that is still in development.

Unfortunatly I did not log the changes that I did make as I added them. This means That I will need to back track and find all files needing changes and log the process. Give me a few days and I will package up the changes needed and contribute it as a mod.

martinmacca I pm'd you a little more info on this subject. Will post when I finished logging the changes. Any one wanting to test this out LET ME KNOW!
:)

#19   chardae

chardae
  • Members
  • 73 posts

Posted 03 October 2004 - 10:37

I believe I have the entire instructions complete. I need a few people to test it out for errors. Willing parties can email/pm me to let me know how It installs. Please be specific if errors are found. You download it at the contributions.

Extra Address Line Contribution
:)

#20   ElLeonBlanco

ElLeonBlanco
  • Members
  • 77 posts

Posted 05 October 2004 - 02:08

I find the instructions are very well written for this contrib. But... I seem to have fallen into the pit of: "I can't quite get this one thing to work." I can get the text fields to work perfectly. When I enter data it updates and displays in the customer's information.

Now here is my problem:

I have added several radio buttons to my customer information. When you select Yes or No it updates the database columns that correspond to the input. But when I go to account edit I can not seem to get the existing selection to display and I end up with all blank radio buttons. (text fields are working) I have tried to figure it out by looking at the code for the gender button which works. I am sure I have overlooked something fairly obvious. /pinch.gif' class='bbc_emoticon' alt='>_<' />

Any ideas?
ElLeonBlanco

"The man of genius makes no mistakes. His errors are volitional and are the portals of discovery." James Joyce (18821941)