Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding Custom Fields to Customer Details


Guest

Recommended Posts

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 ;), 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 ;)) 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') . ' ' . (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_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. ;)

 

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!!

Link to comment
Share on other sites

  • Replies 84
  • Created
  • Last Reply

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, :)

Link to comment
Share on other sites

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) . ' ' . (tep_not_null(CUSTOMER_COMMENTS_TEXT) ? '<span class="inputRequirement"><br>' . CUSTOMER_COMMENTS_TEXT . '</span>': ''); ?></td>

             </tr>

           </table></td>

         </tr>

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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 :D

 

Regards,

 

Mike

Link to comment
Share on other sites

  • 4 weeks later...

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 ?

editaccount.jpg

accountaddy.jpg

Link to comment
Share on other sites

:'( 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!

Link to comment
Share on other sites

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. >_<

 

Any ideas?

ElLeonBlanco

 

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

Link to comment
Share on other sites

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. >_<

 

Any ideas?

 

Well... it wasn't so obvious.. but as usual persistance and a lot of trial and error paid off. :D

ElLeonBlanco

 

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

Link to comment
Share on other sites

  • 2 weeks later...

It would be WONDERFUL if there were something in the osC Admin for Admin Notes.

 

Like a text box that gets saved into the database. When you add something and hit submit, it will be forever saved in the database until you update it or clear the notes contents.

 

Does anyone know of a contribution (I looked and did not find anything) or how to do this?

 

I have installed a TON of MODs and some have problems. I do not want to rip them out so I need to make notes about them.

 

Then if I need to change something and then change it back on the site, I need to make a note about it.

 

Then if I need to make myself a quick note about an order or supplier, then I need to do that as well.

 

Basically, I want my notes to be in the osC Admin instead of on a bunch of pieces of paper on my desk and this way, I will have access to my notes on other computers like when I am at work or whatever.

 

This is really important to me if it can be done.

L8r,

PopTheTop

 

Published osC Contributions:

- eCheck Payment Module v3.1

- Reviews in Product Display v2.0

- Fancier Invoice & Packingslip v6.1

- Admin Notes / Customer Notes v2.2

- Customer Zip & State Validation v2.2

- Search Box with Dropdown Category Menu v1.0

 

Pop your camper's top today!

It's a popup thing...

You wouldn't understand

Link to comment
Share on other sites

It would be WONDERFUL if there were something in the osC Admin for Admin Notes.

 

Like a text box that gets saved into the database. When you add something and hit submit, it will be forever saved in the database until you update it or clear the notes contents.

 

Does anyone know of a contribution (I looked and did not find anything) or how to do this?

 

I have installed a TON of MODs and some have problems. I do not want to rip them out so I need to make notes about them.

 

Then if I need to change something and then change it back on the site, I need to make a note about it.

 

Then if I need to make myself a quick note about an order or supplier, then I need to do that as well.

 

Basically, I want my notes to be in the osC Admin instead of on a bunch of pieces of paper on my desk and this way, I will have access to my notes on other computers like when I am at work or whatever.

 

This is really important to me if it can be done.

 

---TIP QUICK AND DIRTY---

 

for a simple an easy solution install define mainpage and dont install it to php files in your catalog, just add the define mainpage file to your language folder.

if you allready have define mainpage running on your site, open the file and rename all defines to note. that should do the trick

 

greetz john

Link to comment
Share on other sites

Thanks, but actually I am lost reading your reply. I am not a programmer and just learning as I go while installing various MODs. Can you be more specific as to what you said and then, how do I use it?

L8r,

PopTheTop

 

Published osC Contributions:

- eCheck Payment Module v3.1

- Reviews in Product Display v2.0

- Fancier Invoice & Packingslip v6.1

- Admin Notes / Customer Notes v2.2

- Customer Zip & State Validation v2.2

- Search Box with Dropdown Category Menu v1.0

 

Pop your camper's top today!

It's a popup thing...

You wouldn't understand

Link to comment
Share on other sites

  • 3 weeks later...

I have decided to tackle this one on my own. Go HERE to get it

 

Admin Notes v1.0

 

Works great!

L8r,

PopTheTop

 

Published osC Contributions:

- eCheck Payment Module v3.1

- Reviews in Product Display v2.0

- Fancier Invoice & Packingslip v6.1

- Admin Notes / Customer Notes v2.2

- Customer Zip & State Validation v2.2

- Search Box with Dropdown Category Menu v1.0

 

Pop your camper's top today!

It's a popup thing...

You wouldn't understand

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...