Getting Customers Firstname

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

I am making a customer Payment Plugin my processor request the customer's name in the format first name and a new field is last name.  I found how to get the full name but is there away to access each individually?
6 years ago
jbudd3681 wrote:
Hello All,

I am making a customer Payment Plugin my processor request the customer's name in the format first name and a new field is last name.  I found how to get the full name but is there away to access each individually?


Hello,

You can do following way.


var firstName = customer.GetAttribute<string>( SystemCustomerAttributeNames.FirstName );
var lastName = customer.GetAttribute<string>( SystemCustomerAttributeNames.LastName );


Please don't duplicate forum post.

Here you can find same post.

https://www.nopcommerce.com/boards/t/18516/firstname-and-lastname-as-part-of-the-customer-entity.aspx
6 years ago
Thanks for your help! sorry for the duplication I shall work on my searching keywords.
6 years ago
jbudd3681 wrote:
Thanks for your help! sorry for the duplication I shall work on my searching keywords.


Your welcome..!!

Yahh working on that.
5 years ago
That solution doesn't work with 4.10. Any advice?


public void HandleEvent(EntityUpdatedEvent<Customer> eventMessage) {

     var customer = eventMessage.Entity;

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

}


'Customer' does not contain a definition for 'GetAttribute' and no extension method 'GetAttribute' accepting a first argument of type 'Customer' could be found (are you missing a using directive or an assembly reference?)
5 years ago
For anyone wondering how to do this via a Plugin.



        public void HandleEvent(EntityUpdatedEvent<Customer> eventMessage)
        {
            var customer = eventMessage.Entity;

            var firstName = _genericAttributeService.GetAttributesForEntity(customer.Id, "FirstName");
            var lastName = _genericAttributeService.GetAttributesForEntity(customer.Id, "LastName");
            var dateOfBirth = _genericAttributeService.GetAttributesForEntity(customer.Id, "DateOfBirth");
        }

5 years ago
JamieSellars wrote:
For anyone wondering how to do this via a Plugin.



        public void HandleEvent(EntityUpdatedEvent<Customer> eventMessage)
        {
            var customer = eventMessage.Entity;

            var firstName = _genericAttributeService.GetAttributesForEntity(customer.Id, "FirstName");
            var lastName = _genericAttributeService.GetAttributesForEntity(customer.Id, "LastName");
            var dateOfBirth = _genericAttributeService.GetAttributesForEntity(customer.Id, "DateOfBirth");
        }




hello,

yes this is indeed right but whenever any customer update at that time this code is working.

if you have customer id than simply use below code.


   var firstName = _genericAttributeService.GetAttributesForEntity(customer.Id, "FirstName");
4 years ago
sk5202 wrote:

Hello,

You can do following way.


Hello!

Could you help me in telling me how to get the 'gender' attribute from a view in Nop 4.1? In specific i need it on HeaderLinks\Default.cshtml


Thanks in advanced!
4 years ago
If the model does not already have it, then you need to use Resolve() in the view to use the service.  
(I'm not 100% sure about these usings for 4.10, and this assumes the Model does have CustomerId )


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

@{
    var genericAttributeService = EngineContext.Current.Resolve<IGenericAttributeService>();
    var gender = _genericAttributeService.GetAttributesForEntity(Model.CustoerId, "Gender");
}
4 years ago
Thanks NY,

Model does not have it neither 'customerId' yet. This works but with a few adds it was as follows:

@{
   var customer = EngineContext.Current.Resolve<Nop.Core.IWorkContext>().CurrentCustomer;
   var genericAttributeService = EngineContext.Current.Resolve<IGenericAttributeService>();
   var attribute = genericAttributeService.GetAttributesForEntity(customer.Id, "Customer").Where(x => x.Key == "Gender").ToList();
   string gender = attribute[0].Value;
}


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