Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Adding the user's name to a sidebox

Adding the user's name to a sidebox

Locked

Views: 726

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
3 May 2009, 4:38 AM
#1
frankderosa avatar

frankderosa

New Zenner

Join Date:
Jan 2009
Location:
Charlottesville, VA
Posts:
51
Plugin Contributions:
0

Adding the user's name to a sidebox

I'm customizing a sideblock for a site I am working on. When a user is logged in, I want to show their username in a short greeting message. I thought I had it working with $username, but that doesn't seem to work anymore.

I've tried quite a bit of checking and searching but "user" is too short a word to search for, so that's made searching difficult.

Any help?

Thanks!
Frank

3 May 2009, 8:24 PM
#2
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding the user's name to a sidebox

It depends whether you want the username, or the user's name....

If you just want the user's name, as in the firstname of the customer, then you can use this code:

if (isset($_SESSION['customer_id'])) { // check the customer is actually logged in
  echo $_SESSION['customer_first_name'] .' ' . $_SESSION['customer_last_name']; // show the name variables you want to use
}

If you want the username (customers_nickname), then you would need to use the customer_id and query the database to get the customer field.

Absolute

3 May 2009, 10:30 PM
#3
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Adding the user's name to a sidebox

Just been pointed out that customer_last_name may not be available to you to use.

I would just like to add that this is in fact set within includes/modules/pages/login/header_php.php on line 88:

$_SESSION['customer_last_name'] = $check_customer->fields['customers_lastname']; 

So my suggestion would be either "try" the code I listed above, or use a database query to return the fields you require from the database, using the $_SESSION['customer_id'] as the key.

Absolute

4 May 2009, 4:43 AM
#4
frankderosa avatar

frankderosa

New Zenner

Join Date:
Jan 2009
Location:
Charlottesville, VA
Posts:
51
Plugin Contributions:
0

Re: Adding the user's name to a sidebox

Your first suggestion worked perfectly. I double checked in the includes/modules/pages/login/header_php.php file and it has the query for both first and last names, and I have no plans to change it.

Thanks! This is exactly what I needed.

Frank