FirstName and LastName as part of the Customer entity

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Would be nice to capture FirstName and LastName in Customer entity. There are lots of uses for this. One is to welcome the user more personally at login

E.g.

Welcome Back Darren Pegram (not Darren Pegram? click here to logout)
11 years ago
It's already there as part of Address
11 years ago
keesjan wrote:
It's already there as part of Address


A customer can have many addresses. So which one would you use in the scenario I gave?

You need a FirstName and LastName as attributes of the Customer entity
11 years ago
Good point, so when you register as a new customer you are asked for your firstname & lastname.
Looking at the code, I can see its stored as a systemattribute. As a quick test I added this
to CommonController.HeaderLinks (just before the return PartialView(model);


var firstName = customer.GetAttribute<string>( SystemCustomerAttributeNames.FirstName );
var lastName = customer.GetAttribute<string>( SystemCustomerAttributeNames.LastName );
model.CustomerEmailUsername = firstName + " " + lastName ;


This will display firstname and lastname
11 years ago
keesjan wrote:
Good point, so when you register as a new customer you are asked for your firstname & lastname.
Looking at the code, I can see its stored as a systemattribute. As a quick test I added this
to CommonController.HeaderLinks (just before the return PartialView(model);


var firstName = customer.GetAttribute<string>( SystemCustomerAttributeNames.FirstName );
var lastName = customer.GetAttribute<string>( SystemCustomerAttributeNames.LastName );
model.CustomerEmailUsername = firstName + " " + lastName ;


This will display firstname and lastname


Thanks V. much.

Any idea which table this is stored in the Db?
11 years ago
GenericAttribute ( see GenericAttributeService.cs )
10 years ago
keesjan wrote:
Good point, so when you register as a new customer you are asked for your firstname & lastname.
Looking at the code, I can see its stored as a systemattribute. As a quick test I added this
to CommonController.HeaderLinks (just before the return PartialView(model);


var firstName = customer.GetAttribute<string>( SystemCustomerAttributeNames.FirstName );
var lastName = customer.GetAttribute<string>( SystemCustomerAttributeNames.LastName );
model.CustomerEmailUsername = firstName + " " + lastName ;


This will display firstname and lastname


I tried this, but it still displayed the email and not first/last name. Is there anything else that I need to do?

Thanks so much!
Fred
10 years ago
clubfredd wrote:


I tried this, but it still displayed the email and not first/last name.


In the admin area, Configuration > Settings > Customer Setting

have you selected show full names, maybe you have show emails selected?
10 years ago
Yes sir, I had already set it to view Customer Name Format to Show Full Names but still showed email. Even if I change to anything else other than Show Emails it does not change the display at the top.

Weird because before I even changed this it was already set to Show First Names.
10 years ago
keesjan wrote:
...


var firstName = customer.GetAttribute<string>( SystemCustomerAttributeNames.FirstName );
var lastName = customer.GetAttribute<string>( SystemCustomerAttributeNames.LastName );
model.CustomerEmailUsername = firstName + " " + lastName ;


This will display firstname and lastname


Just to verify that I did this correctly, I put the code above inside /Controllers/CommonControllers.cs as below. Is this correct?:


var model = new HeaderLinksModel()
          {
                IsAuthenticated = customer.IsRegistered(),
                CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",
                ShoppingCartEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart),
                ShoppingCartItems = customer.ShoppingCartItems
                    .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
                    .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id)
                    .ToList()
                    .GetTotalProducts(),
                WishlistEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableWishlist),
                WishlistItems = customer.ShoppingCartItems
                    .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist)
                    .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id)
                    .ToList()
                    .GetTotalProducts(),
                AllowPrivateMessages = customer.IsRegistered() && _forumSettings.AllowPrivateMessages,
                UnreadPrivateMessages = unreadMessage,
                AlertMessage = alertMessage,
            
        
  };

  var firstName = customer.GetAttribute<string>( SystemCustomerAttributeNames.FirstName );
  var lastName = customer.GetAttribute<string>( SystemCustomerAttributeNames.LastName );
  model.CustomerEmailUsername = firstName + " " + lastName ;
      

  return PartialView(model);


Still does not show the First and Last name :(
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.