Check if logged in through the Root.cshtml nop 2.3

9 年 前
is there a way to Check if logged in through the Root.cshtml nop 2.3
if the visitor is logged in I will display a different menu than if they are not logged in.
9 年 前
scripter wrote:
is there a way to Check if logged in through the Root.cshtml nop 2.3
if the visitor is logged in I will display a different menu than if they are not logged in.


Sure. I've provided some sample code (untested).


@{

using Nop.Core;
using Nop.Core.Infrastructure;
using Nop.Services.Customers;
            bool isRegistered = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsRegistered();
}


p.s.

I this logic is better suited for an action instead of the view and the pass the value to the view that is responsible for determining which menu to use.
9 年 前
I have done what you suggested which appears to work but when I try to do a If statement to determine which partial header to put on it blows up my page.

Here is my if statement which is where I am pretty sure the problem is

@{
                if (isRegistered)
                {
                    Html.Partial("HeaderLoggedin");
                }
                else
                {
                    Html.Partial("Header");
                }
            }

if you see what is wrong with this please let me know
9 年 前
scripter wrote:
I have done what you suggested which appears to work but when I try to do a If statement to determine which partial header to put on it blows up my page.

Here is my if statement which is where I am pretty sure the problem is

@{
                if (isRegistered)
                {
                    Html.Partial("HeaderLoggedin");
                }
                else
                {
                    Html.Partial("Header");
                }
            }

if you see what is wrong with this please let me know


Can you provide the error message and stack trace? At first glance it looks right (although you might have semicolons render too).
9 年 前
skyler.severns wrote:
I have done what you suggested which appears to work but when I try to do a If statement to determine which partial header to put on it blows up my page.

Here is my if statement which is where I am pretty sure the problem is

@{
                if (isRegistered)
                {
                    Html.Partial("HeaderLoggedin");
                }
                else
                {
                    Html.Partial("Header");
                }
            }

if you see what is wrong with this please let me know

Can you provide the error message and stack trace? At first glance it looks right (although you might have semicolons render too).



Its not giving error but just not rendering the Header at all
The If statement just is not being processed like I thought it would.
if I didnt include the semicolons then it errors on me so that I why I added them
9 年 前
Figured out that problem
I did not include the @ symbol in there



@{
                if (isRegistered)
                {
                    @Html.Partial("HeaderLoggedin");
                }
                else
                {
                    @Html.Partial("Header");
                }
            }
9 年 前
Thank you so much for your help. This is my first shot at this new NopCommerce and with Razor so this is a huge learning experience for me..
1 个月 前
Hi there,
I found method which is working in 4.30

var isRegisterCustomer = customerService.IsRegistered(workContext.CurrentCustomer);


to have this worked you have to include few lines into your Razor view
@using Nop.Core
@using Nop.Services.Customers

@inject IWorkContext workContext
@inject ICustomerService customerService