Page 1 of 1
$User.FirstName not parsing
Posted: Tue Feb 14, 2012 9:28 am
by moustafa
Hi,
I have the following snippet of HTML in a layout:
Code: Select all
<div id="accountlinks">
#if($customer.IsAnonymous)
<a class="selectablelink" href="~/Login.aspx">SIGN IN</a>
#else
<p display="inline" id="welcometext">
Welcome, $User.FirstName!
<a class="selectablelink" href="~/Logout.aspx">SIGN OUT</a> | <a class="selectablelink" href="~/Members/MyAccount.aspx">MY ACCOUNT</a></p>
#end
</div>
It correctly displays the login vs. logout links depending on whether the customer is logged in. However, it does not display the customer's name. I also tried ${User.FirstName} but no luck there either.
Any help?
Thanks,
Moustafa
Re: $User.FirstName not parsing
Posted: Tue Feb 14, 2012 9:29 am
by moustafa
Just to clarify, it literally displays "$User.FirstName" instead of the customer's name.
Re: $User.FirstName not parsing
Posted: Tue Feb 14, 2012 11:28 am
by david-ebt
We use this code:
Code: Select all
#if(!$customer.IsAnonymous)
Welcome back ${customer.PrimaryAddress.FirstName}
#end
Re: $User.FirstName not parsing
Posted: Wed Feb 15, 2012 12:18 am
by moustafa
Thanks, this works, but requires the user to have a primary address and name set up. I didn't have this set up for my own account b/c I am an admin. After I added an address it worked fine.
So the question is whether it's possible for regular customers to have an account without a primary address? If so, this isn't ideal.
Thanks again,
Moustafa
Re: $User.FirstName not parsing
Posted: Wed Feb 15, 2012 10:52 am
by david-ebt
If you look at the data structure, the ac_Users table doesn't contain first name or last name. The only way a user has a name is through their primary address, a billing address or a shipping address. If you have access to the SQL Server for your AC store you can run this query and it show you the first name and last name for all users who are not anonymous users.
Code: Select all
select u.UserId, u.UserName, a.FirstName, a.LastName
from ac_Users u
left join ac_Addresses a on u.PrimaryAddressId = a.AddressId
where u.IsAnonymous = 0
In our sites the only users that didn't have a primary address where those who had registered but not order.
Re: $User.FirstName not parsing
Posted: Thu Feb 16, 2012 7:58 am
by moustafa
OK, so I guess it'll have to do. Maybe I'll add some logic in the future to make sure the name is defined before displaying the welcome message.
Thanks for your very helpful answers.
Moustafa
Re: $User.FirstName not parsing
Posted: Thu Feb 16, 2012 8:44 am
by jmestep
If you do it in a conlib, you could do something like this- show the name for non-anonymous users only.
Code: Select all
if(!Token.Instance.User.IsAnonymous)
{
if(Token.Instance.User.UserName.IndexOf("@domain.xyz") == -1)
UserNameLabel.Text = "Hello, " + Token.Instance.User.PrimaryAddress.FirstName
}
It would probably be something like $User.PrimaryAddress.FirstName in nVelocity.