Welcome customer name on main page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
Hello, I was using V3.70 and just upgraded to the latest V4.5.1 and the welcome customer name don't work any more here is the code I was using
@using Nop.Core
@using Nop.Core.Domain.Customers
@using Nop.Core.Infrastructure
@using Nop.Services.Common
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";
}
<div class="page home-page">
    <div class="page-body">
     @{
            var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
            if (!currentCustomer.IsGuest())
            {
                var name = currentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);
                if (!string.IsNullOrEmpty(name))
                {
                    <div style="font-size:22px; color:red;">
                        <div id="addcustname" style="display: inline-block; ">Welcome:</div> <div id="custname" style="font-weight:bold;display: inline-block;">@name!</div>
                        <br/><br />
                    </div>
                }
            }
        }
        @Html.Widget("home_page_top")
        @Html.Action("TopicBlock", "Topic", new { systemName = "HomePageText" })
        @Html.Widget("home_page_before_categories")
        @Html.Action("HomepageCategories", "Catalog")
        @Html.Widget("home_page_before_products")
        @Html.Action("HomepageProducts", "Product")
        @Html.Widget("home_page_before_best_sellers")
        @Html.Action("HomepageBestSellers", "Product")
        @Html.Widget("home_page_before_news")
        @Html.Action("HomePageNews", "News")
        @Html.Widget("home_page_before_poll")
        @Html.Action("HomePagePolls", "Poll")
        @Html.Widget("home_page_bottom")
    </div>
</div>  


Any way I can implement the same on this new version

Thanks!
2 years ago
Yes things have chanegd a bit since 3.7

Thy this

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

@{
    var workContext = EngineContext.Current.Resolve<IWorkContext>();
    var customerService = EngineContext.Current.Resolve<ICustomerService>();

    var customer = await workContext.GetCurrentCustomerAsync();
    if (customer != null)
    {
        var isGuest = await customerService.IsGuestAsync(customer);
        if (!isGuest)
        {
            var fullName = await customerService.GetCustomerFullNameAsync(customer);
            if (!string.IsNullOrEmpty(fullName))
            {
                <div style="font-size:22px; color:red;">
                    <div id="addcustname" style="display: inline-block; ">
                        Welcome:</div> <div id="custname" style="font-weight:bold;display: inline-block;">@fullName!</div>
                    <br/><br />
                </div>
            }
        }
    }
}


You can search existing code base for other elements that might have changed :)
2 years ago
Thank You Andrew,  just some adjustments on CSS and worked perfectly.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.