How to personalize homepage by adding customer’s name in nopCommerce

The magic of creating personalize experience comes from the data. Many store owners do not make use of the customer data that they already have in their database. Making use of existing data and creating a personalize experienced for online shoppers is a great way to bring back existing customers to your store site.

Statistics shows that consumers like when online stores offers personalize messages and offers. User data can be used in several ways to personalize the communication between the online store and the potential buyers.

Today, we will discuss how to personalize homepage by adding customer’s name to it in nopCommerce.

Go to: Nop.Web / Views / Home / Index.cshtml

Open the file “Index.cshtml” and add this code at the top:

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

By adding the above code, we are simply loading the customer data from the database. Once, we have the data loaded, we can display it in any way (or anywhere).

Add the following code on the same “Index.cshtml” page (in the body where you would like to display the customer’s name):

            var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
            if (!currentCustomer.IsGuest())
                var name = currentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);
                if (!string.IsNullOrEmpty(name))
                    <div id="customnameLabel" style="display: inline-block;">YourStore Welcomes You:</div> <div id="customnameValue" style="font-weight:bold;display: inline-block;">@name</div>

In this example, we are adding the customer’s “first name” (pulling it from the database).

 Here is the output:

A copy of this article is also available on Arvixe Blog.

About Author

Written By Lavish Kumar

Based out of New York, USA, Lavish Kumar is a full stack web developer by profession and founder of Striving Programmers, a trusted community for developers that offers a wealth of articles and forums to assist individuals with improving their software development skills.

Leave your comment