$User.FirstName not parsing

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
Post Reply
moustafa
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Wed Oct 19, 2011 9:54 pm

$User.FirstName not parsing

Post by moustafa » Tue Feb 14, 2012 9:28 am

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

moustafa
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Wed Oct 19, 2011 9:54 pm

Re: $User.FirstName not parsing

Post by moustafa » Tue Feb 14, 2012 9:29 am

Just to clarify, it literally displays "$User.FirstName" instead of the customer's name.

User avatar
david-ebt
Captain (CAPT)
Captain (CAPT)
Posts: 253
Joined: Fri Dec 31, 2010 10:12 am

Re: $User.FirstName not parsing

Post by david-ebt » Tue Feb 14, 2012 11:28 am

We use this code:

Code: Select all

#if(!$customer.IsAnonymous)
    Welcome back ${customer.PrimaryAddress.FirstName}
#end
David
http://www.ecombuildertoday.com
Enhanced Reporting for AbleCommerce
Image

moustafa
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Wed Oct 19, 2011 9:54 pm

Re: $User.FirstName not parsing

Post by moustafa » Wed Feb 15, 2012 12:18 am

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

User avatar
david-ebt
Captain (CAPT)
Captain (CAPT)
Posts: 253
Joined: Fri Dec 31, 2010 10:12 am

Re: $User.FirstName not parsing

Post by david-ebt » Wed Feb 15, 2012 10:52 am

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.
David
http://www.ecombuildertoday.com
Enhanced Reporting for AbleCommerce
Image

moustafa
Lieutenant (LT)
Lieutenant (LT)
Posts: 54
Joined: Wed Oct 19, 2011 9:54 pm

Re: $User.FirstName not parsing

Post by moustafa » Thu Feb 16, 2012 7:58 am

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

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: $User.FirstName not parsing

Post by jmestep » Thu Feb 16, 2012 8:44 am

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.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Post Reply