Customer name when logged in not email?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
satishbhuktar wrote:
How to do the same with Nopcommerce 3.7? i search for Module folder. it is not present in nop 3.7. Please help. i want to First name insted of Email in header.

If you want to show customer first name in the header you should put the following string

CustomerEmailUsername = customer.IsRegistered() ? customer.FormatUserName() : "",

instead of

CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",

in the HeaderLinks method of the CommonController (line 386)

And check the following setting in the admin area -> Configuration -> Settings -> Customer Settings:
Customer name format -> Show first name
8 years ago
I think you have nosource file.
Then go to Nop.web->views->common->header.cshtml
add this code to up

@using Nop.Core.Infrastructure;
@using Nop.Core;
@using Nop.Core.Domain.Customers;
@using Nop.Services.Common;

And then add this code

@if (Model.IsAuthenticated)
        {

            var FirstName = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); ;
            <li><a href="@Url.RouteUrl("CustomerInfo")" class="ico-account">@FirstName</a></li>
            <li><a href="@Url.RouteUrl("Logout")" class="ico-logout">@T("Account.Logout")</a></li>
        }
8 years ago
you have to add 1 property to ur Header link Model for set the Name .
and have to modify ur Commancontroller for model HeaderLinksModel.
use @Modal.Name in the HeaderLinks.chtml

Just try replace code  for HeaderLinksModel with this in controller.

//getting user name using for loop
            string FirstName = null;
            foreach (var item in customer.Addresses)
            {
                 FirstName = item.FirstName;
            }
                
            var model = new HeaderLinksModel
            {
                IsAuthenticated = customer.IsRegistered(),
                CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",
                Name = customer.IsRegistered() ? FirstName : "", //use here
                ShoppingCartEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart),
                WishlistEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableWishlist),
                AllowPrivateMessages = customer.IsRegistered() && _forumSettings.AllowPrivateMessages,
                UnreadPrivateMessages = unreadMessage,
                AlertMessage = alertMessage,
            };
8 years ago
anik1991 wrote:
I think you have nosource file.
Then go to Nop.web->views->common->header.cshtml
add this code to up

@using Nop.Core.Infrastructure;
@using Nop.Core;
@using Nop.Core.Domain.Customers;
@using Nop.Services.Common;

And then add this code

@if (Model.IsAuthenticated)
        {

            var FirstName = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); ;
            <li><a href="@Url.RouteUrl("CustomerInfo")" class="ico-account">@FirstName</a></li>
            <li><a href="@Url.RouteUrl("Logout")" class="ico-logout">@T("Account.Logout")</a></li>
        }


Little correction Dear Anik. File name: HeaderLinks.cshtml
if you use any theme
Path:  Themes\{ThemeName}\Views\Common\HeaderLinks.cshtml
8 years ago
Mariann my enable uername is set to false. so i tried this 1. & thanks Anik
8 years ago
satishbhuktar wrote:
you have to add 1 property to ur Header link Model for set the Name .
and have to modify ur Commancontroller for model HeaderLinksModel.
use @Modal.Name in the HeaderLinks.chtml

Just try replace code  for HeaderLinksModel with this in controller.

//getting user name using for loop
            string FirstName = null;
            foreach (var item in customer.Addresses)
            {
                 FirstName = item.FirstName;
            }
                
            var model = new HeaderLinksModel
            {
                IsAuthenticated = customer.IsRegistered(),
                CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "",
                Name = customer.IsRegistered() ? FirstName : "", //use here
                ShoppingCartEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart),
                WishlistEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableWishlist),
                AllowPrivateMessages = customer.IsRegistered() && _forumSettings.AllowPrivateMessages,
                UnreadPrivateMessages = unreadMessage,
                AlertMessage = alertMessage,
            };

You can optimize your code. If you have 100 addresses for one customer then loop goes for 100 times. And if a customer does not have any address in that case you dont get any first name.
In that case you can get first name by this code

FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);

It will less your run time huge.
And thanks Mr.Sohel
7 years ago
I don't understand why everyone on this forum thread is discussing how to change the code. Why doesn't this feature just work with a stable build of nopCommerce? I've recently installed the latest 3.8 and it definitely is still broken. Can we list this in the bugs/defects to be fixed in an upcoming build? This really seems very trivial and it is my opinion that it should just work correctly without users/customers having to edit their code.

Michael
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.