Hi, how can i check the value of a customer custom attribute? say i created an attribute called <Is Preferred> and its type of dropdown with "yes" and "no" values.
how can i get the value of Is Preferred attribute for a signed in customer?
thanks
ps: is it possible to search in forum topics? cant seem to find a search feature.
Hi, how can i check the value of a customer custom attribute? say i created an attribute called <Is Preferred> and its type of dropdown with "yes" and "no" values.
how can i get the value of Is Preferred attribute for a signed in customer?
thanks
ps: is it possible to search in forum topics? cant seem to find a search feature.
Hi,
You can use the GetAttribute extension method from GenericAttributeExtensions class. Here is an example:
thanks for the reply. so that attribute key is the name i pick with spaces moved? if my custom attribute name is <Is Preferred Customer> the key is "IsPreferredCustomer", right?
I think the code Hristian posted is actually just to retrieve a generic attribute associated with the customer. If you're talking about a Custom customer attribute that can be defined from the Customer form fields tab on the Customer Settings page then it's a bit different as multiple attributes are stored in an XML format.
The XML is still stored as a generic attribute so it starts the same:
var customAttributesXml = customer.GetAttribute<string>(SystemCustomerAttributeNames.CustomCustomerAttributes)
Which should return an XML representation of the customer's custom attributes which you'll need to parse to get the one you're interested in. I haven't tried it but I'd guess that you need one of the functions in the CustomerAttributeParser so possibly something like:
var isPreferredValue = ParseValues(customAttributesXml, {customerAttributeId}).FirstOrDefault()
Where {customerAttributeId} is the integer Id of the Custom customer attribute that you created in the admin site.