How to display the Customer ID on customer account page?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hello.

Using nopCommerce 3.90, Default theme.

How to display Customer ID on the account page?

No source code.., please...

Thanks.
6 years ago
Hi,

You can get the ID in any cshtml file (you need \Views\Customer\Info.cshtml) the following way:
Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id
6 years ago
a.m. wrote:
Hi,

You can get the ID in any cshtml file (you need \Views\Customer\Info.cshtml) the following way:
Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id


Where do I put it? And how do I call the ID?

I've tried your code, shows the same code at front-end...
6 years ago
zaf wrote:
Where do I put it? And how do I call the ID?

If you want to display it on the customer info page, then you should edit \Views\Customer\Info.cshtml file. In you're asking about a certain line of code, then it depends on where exactly you want to place it (only you know it)

zaf wrote:
And how do I call the ID?

I've tried your code, shows the same code at front-end...

If you want to render it in markup (not in brackets where C# code is placed), then use @
@Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id
6 years ago
Unfortunatelly, it doesn't work. Tried as you suggested. Didn't work...(
6 years ago
Would you post the .cshtml page (or at least the line and some surrounding lines)?
6 years ago
Putting this in my Info.cshtml page, in the location that I wanted it, worked for me:

@(Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id)
6 years ago
becandoo wrote:
Putting this in my Info.cshtml page, in the location that I wanted it, worked for me:

@(Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id)


Thank you, but I didn't really undesrtand how to it... I tried different ways...
6 years ago
zaf wrote:
Putting this in my Info.cshtml page, in the location that I wanted it, worked for me:

@(Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id)

Thank you, but I didn't really undesrtand how to it... I tried different ways...


Open the /views/customer/info.cshtml file with notepad. Locate a div somewhere on the page that you recognize and want the ID to appear.


Example:

<div class="page-title"><h1>My account - Customer info</h1></div>
<div class="YourNewCustomerIdClass">@(Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id)</div>


And in your stylesheet, you need to create the new class to set the font and position parameters:
.YourNewCustomerIdClass {
    text-align: right;
    font-size: 12px;
    padding: 0 10px 0 10px;
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.