Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Show customers first AND lastname ?


wheeloftime

Recommended Posts

Posted

I have been strugling with this for quite some time now but I can't seem to figure it out.

What I would like to do is to show the customers first and last name when they login. Right now it only shows 'first name' and that looks silly when someone created an account with Mrs. A for first name.

I found in catalog/includes/functions/general.php the function tep_customer_greeting and thought to simply add the return string with the customer last name.

Well, NOT :(

 

Originally it looks like

function tep_customer_greeting() {
   global $customer_id, $customer_first_name;

   if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {

     $greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name),tep_href_link(FILENAME_PRODUCTS_NEW));
   } else {
     $greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
   }

   return $greeting_string;
 }

 

I added a global $customer_last_name and added also tep_output_string_protected($customer_last_name) to the $greeting_string= part.

That didn't work so I did a (tep_session_is_registered('customer_last_name') expecting this would get the customers last name like it seems to do with the first name. That didn't work either however as the $customer_last_name just stays empty. As a ressort I suppose I could do a seperate query for the last name but it feels as if that is not needed and I am just not aware enough yet how things interact within osC. Is there a simple way like in the line as this function has been build or should the last name really be querried ?

 

Thanks in advance for any help and Merry Christmas !

Posted

Hello Paul,

 

I speak Dutch as I am Dutch but for the sake of the English forum I'll stick to English.

I just found your message and have looked at the Dutch thread. Next time I should look there first also I think as your changes work perfectly :thumbsup:

I am very happy with the general solution so the variables are available where ever you are and the touch to the contact_us page is great also !

Reading the thread I believe no one uses the original osC entry anymore but even with a login box this is handy.

Thanks for your very fast reply and of course the ultimate solution to this 'problem' !

 

 

Cheers and 'see you' on the Dutch or English board !

Posted
Hi Howard,

 

you speak Dutch too don't you?

 

There has been a discussion about it on the Dutch forums a while ago:

http://www.oscommerce.nl/forums/index.php?...st=0entry6762

 

A working solution has been posted over there.

 

edit: Merry Christmas to you too of course :)

 

Okay, for those who are not that good in Dutch I'll show the working solution as given in the Dutch forum and which works very well. It's Paul's solution so all thanks should go to him !

 

One option to have the lastname shown for a customer would be to change the greetuser function only but the underneath solution takes a slightly other way and will give you more options and control to show the lastname and email address also.

 

First two changes are within the catalog/login.php:

First find the $check_customer_query part

// Check if email exists
//    $check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
// add costumer details (1/2) paulm 2004/04/02, above line replaced by:
  $check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id, customers_lastname from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");

Comment out the existing query and replace it with the one shown or manually add 'customers_lastname' to the existing query just before the 'from'.

 

Second:

A little below you will find

        $customer_id = $check_customer['customers_id'];
      $customer_default_address_id = $check_customer['customers_default_address_id'];
      $customer_first_name = $check_customer['customers_firstname'];
      $customer_country_id = $check_country['entry_country_id'];
      $customer_zone_id = $check_country['entry_zone_id'];
      tep_session_register('customer_id');
      tep_session_register('customer_default_address_id');
      tep_session_register('customer_first_name');
      tep_session_register('customer_country_id');
      tep_session_register('customer_zone_id');

 

add the following underneath it:

// begin add costumer details (2/2) paulm 2004/04/02
      $customer_last_name = $check_customer['customers_lastname'];
      $customer_email_address = $check_customer['customers_email_address'];
      tep_session_register('customer_last_name');
      tep_session_register('customer_email_address');
// end add costumer details (2/2)

 

this will make sure the customers last name and his/her email address are known throughout the session in every part of osC so you don't have to query seperately for it anymore in case you would like to use this information somewhere else.

 

Last step:

Go to includes/functions/general.php and search for the tep_customer_greeting function (it's somewhere further down). Change it to the following:

////
// Return a customer greeting
function tep_customer_greeting() {
  global $customer_id, $customer_first_name, $customer_last_name;
// add customer details (1/2) paulm 2004/04/02 (added ", $costumer_last_name")

  if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {
//      $greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name), tep_href_link(FILENAME_PRODUCTS_NEW));
// add costumer details (2/2) paulm 2004/04/02, above line replaced by:
    $greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_first_name . ' ' . $customer_last_name), tep_href_link(FILENAME_PRODUCTS_NEW));
  } else {
    $greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
  }

  return $greeting_string;
}

As you see there is a new global variable introduced called $customer_last_name within the first line.

After that comment out the original, or change, the '$greetings_string=...' as shown.

 

That's it !

 

As an extra bonus you can now also change ie. the catalog/contact_us.php to show the customers email address and first/last name filled in by default when they go there (and of course are logged in).

Just add:

// add customer details (1/1) paulm 2004/04/02
if (tep_session_is_registered('customer_id'))
{
  $name = $customer_first_name . ' ' . $customer_last_name;
  $email = $customer_email_address;
}
// end add customer details

to the beginning of the code (just below

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CONTACT_US);

)

and you are done.

 

I hope this will help someone else too.

 

Merry Christmas

  • 4 weeks later...
  • 2 weeks later...
Posted

The file "catalog/create_account.php" also should be slightly modified.

Because if the standard file "create_account.php" is applied: after having created a new account the new customer is greeted with the surname ($last_name) of the previous logged in person.

 

Just add the code between "ADD's" to create_account.php:

 

      if (SESSION_RECREATE == 'True') {
       tep_session_recreate();
     }

     $customer_first_name = $firstname;
// begin: ADD customer details (1/2) paulm 2004/04/02 - Clay Regazzoni =================================
	 $customer_last_name = $lastname; 
     $customer_email_address = $email_address;    
// end:   ADD customer details (1/2) paulm 2004/04/02 - Clay Regazzoni =================================
     $customer_default_address_id = $address_id;
     $customer_country_id = $country;
     $customer_zone_id = $zone_id;
     tep_session_register('customer_id');
     tep_session_register('customer_first_name');
// begin: ADD customer details (2/2) paulm 2004/04/02 - Clay Regazzoni =================================
     tep_session_register('customer_last_name');
     tep_session_register('customer_email_address');
// end:  ADD customer details (2/2) paulm 2004/04/02 - Clay Regazzoni =================================
     tep_session_register('customer_default_address_id');
     tep_session_register('customer_country_id');
     tep_session_register('customer_zone_id');

 

Kind regards,

Clay :)

Posted

I made all of the code changes in their correct places on a brand new OSC installation to test all of this out, and none of it worked. Still only displaying the peach-colored first name on the main front page.

 

???

 

If you would like, visit here to see and I can post the code if necessary.

 

Thanks!

  • 3 weeks later...
Posted

If you have an older 2.2 version you can't use the function:

tep_output_string_protected()

Here's what I did:

////
// Return a customer greeting
function tep_customer_greeting() {
 global $customer_id, $customer_first_name, $customer_last_name;

 if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {

   $greeting_string = sprintf(TEXT_GREETING_PERSONAL, $customer_first_name . ' ' . $customer_last_name, tep_href_link(FILENAME_PRODUCTS_NEW));
 } else {
   $greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));
 }

 return $greeting_string;
}

I also use the same basic code for my login box.

Thanks for this! :thumbsup:

SS:20030317

  • 1 month later...
Posted

Hi guys,

Using all your suggestion, many thanks for that, all worked but one.

 

I have included in my oscommerce a customer title: Mr. Mrs. etc. which works perfectly and send correct confirmation email when created an account like "Dear Mrs Any Name".

 

In the Welcome back page however it shows like:

"Welcome back 2 Any Name" instead of "Welcome back Mrs..."

 

Any suggestions?

 

From general.php:

// Return a customer greeting

function tep_customer_greeting() {

global $customer_id, $customer_title, $customer_first_name, $customer_last_name;

 

if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {

$greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_title . ' ' . $customer_first_name . ' ' . $customer_last_name), tep_href_link(FILENAME_PRODUCTS_NEW));

} else {

$greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));

}

 

return $greeting_string;

}

  • 4 months later...
Posted
Hi guys,

Using all your suggestion, many thanks for that, all worked but one.

 

I have included in my oscommerce a customer title: Mr. Mrs. etc. which works perfectly and send correct confirmation email when created an account like "Dear Mrs Any Name".

 

In the Welcome back page however it shows like:

"Welcome back 2 Any Name" instead of "Welcome back Mrs..."

 

Any suggestions?

 

From general.php:

// Return a customer greeting

  function tep_customer_greeting() {

    global $customer_id, $customer_title, $customer_first_name, $customer_last_name;

 

    if (tep_session_is_registered('customer_first_name') && tep_session_is_registered('customer_id')) {

      $greeting_string = sprintf(TEXT_GREETING_PERSONAL, tep_output_string_protected($customer_title . ' ' . $customer_first_name . ' ' . $customer_last_name), tep_href_link(FILENAME_PRODUCTS_NEW));

    } else {

      $greeting_string = sprintf(TEXT_GREETING_GUEST, tep_href_link(FILENAME_LOGIN, '', 'SSL'), tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL'));

    }

 

    return $greeting_string;

  }

 

 

did you figure that problem out?

well, i inserted what you posted, but nothing happens, it's still only the first name..

 

yours, mark

  • 4 weeks later...
Posted
The file "catalog/create_account.php" also should be slightly modified.

Because if the standard file "create_account.php" is applied: after having created a new account the new customer is greeted with the surname ($last_name) of the previous logged in person.

 

Just add the code between "ADD's" to create_account.php:

 

 ? ? ?if (SESSION_RECREATE == 'True') {
? ? ? ?tep_session_recreate();
? ? ?}

? ? ?$customer_first_name = $firstname;
// begin: ADD customer details (1/2) paulm 2004/04/02 - Clay Regazzoni =================================
?	$customer_last_name = $lastname; 
? ? ?$customer_email_address = $email_address; ? ?
// end: ? ADD customer details (1/2) paulm 2004/04/02 - Clay Regazzoni =================================
? ? ?$customer_default_address_id = $address_id;
? ? ?$customer_country_id = $country;
? ? ?$customer_zone_id = $zone_id;
? ? ?tep_session_register('customer_id');
? ? ?tep_session_register('customer_first_name');
// begin: ADD customer details (2/2) paulm 2004/04/02 - Clay Regazzoni =================================
? ? ?tep_session_register('customer_last_name');
? ? ?tep_session_register('customer_email_address');
// end: ?ADD customer details (2/2) paulm 2004/04/02 - Clay Regazzoni =================================
? ? ?tep_session_register('customer_default_address_id');
? ? ?tep_session_register('customer_country_id');
? ? ?tep_session_register('customer_zone_id');

 

Kind regards,

Clay :)

 

 

anyone can help me where to add these rows?

Archived

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

×
×
  • Create New...