Close

Access and get customer custom values.

eliharel
8 years ago
#9935 Quote
Avatar
  • 3
Hello 
We have a need to access a custom attribute of a customer and pass it to Salesforce
in the CustomerContactTypeConverter class (in the sevenapikes plugin)

we added a few custom attributes in the following manner through Nop

Menu - Configuration->Setting-->Customer Setting
Customer Form Fields Tab
and than new custom Attribute.

So is there a way to access those attribute and get their value by name ? or any other way ?

hoping for a sample code if possible.

Many thanks 


Boyko
8 years ago
#9937 Quote
Avatar
  • Moderator
  • 1570
eliharel wrote:
Hello 
We have a need to access a custom attribute of a customer and pass it to Salesforce
in the CustomerContactTypeConverter class (in the sevenapikes plugin)

we added a few custom attributes in the following manner through Nop

Menu - Configuration->Setting-->Customer Setting
Customer Form Fields Tab
and than new custom Attribute.

So is there a way to access those attribute and get their value by name ? or any other way ?

hoping for a sample code if possible.

Many thanks 




Hi eliharel,

You can see how nopCommerce persists these custom customer attributes and how they are retrieved. You can check the CustomerController as there is the logic of persisting the custom address attributes.

Here is the code from the CustomerController's Create method:

//custom customer attributes
                var customerAttributes = ParseCustomCustomerAttributes(customer, form);
                _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CustomCustomerAttributes, customerAttributes);


The code that retrieves the custom customer attributes can be found in the same controller's PrepareCustomerAttributeModel method.

var selectedCustomerAttributes = customer.GetAttribute<string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService);


I hope this information is useful!
Regards,
Nop-Templates.com Team