{"id":6153,"date":"2017-11-17T12:58:18","date_gmt":"2017-11-17T11:58:18","guid":{"rendered":"http:\/\/jonas.kihlsten.se\/blog\/?p=6153"},"modified":"2017-11-17T12:58:18","modified_gmt":"2017-11-17T11:58:18","slug":"extending-the-customercontact-object-in-episerver-commerce","status":"publish","type":"post","link":"http:\/\/jonas.kihlsten.se\/blog\/2017\/11\/extending-the-customercontact-object-in-episerver-commerce\/","title":{"rendered":"Extending the CustomerContact object in Episerver Commerce"},"content":{"rendered":"<p>Here&#8217;s a quick method for adding your own properties to the CustomerContact object:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic virtual bool AddCustomerContactMetaField(string name, string friendlyName, string type)\r\n        {\r\n            var customerContactMetaClass = DataContext.Current.GetMetaClass(ContactEntity.ClassName);\r\n\r\n            if(customerContactMetaClass.Fields&#x5B;name] != null)\r\n            {\r\n                return false;\r\n            }\r\n            \r\n            return customerContactMetaClass.CreateMetaField(name, friendlyName, type, new Mediachase.BusinessFoundation.Data.Meta.Management.AttributeCollection()) == null;\r\n        }\r\n<\/pre>\n<p>You can then assign and read values to and from your property like this:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nCustomerContact contact = CustomerContact.CreateInstance();\r\n\r\n\/\/ Assign value\r\ncontact.Properties.Add(&quot;MyProperty&quot;, &quot;value&quot;);\r\n\r\n\/\/ Reading a value\r\nstring value = contact.Properties.GetValue&lt;string&gt;(&quot;MyProperty&quot;);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a quick method for adding your own properties to the CustomerContact object: public virtual bool AddCustomerContactMetaField(string name, string friendlyName, string type) { var customerContactMetaClass = DataContext.Current.GetMetaClass(ContactEntity.ClassName); if(customerContactMetaClass.Fields&#x5B;name] != null) { return false; } return customerContactMetaClass.CreateMetaField(name, friendlyName, type, new Mediachase.BusinessFoundation.Data.Meta.Management.AttributeCollection()) == null; } You can then assign and read values to and from your property &hellip; <a href=\"http:\/\/jonas.kihlsten.se\/blog\/2017\/11\/extending-the-customercontact-object-in-episerver-commerce\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Extending the CustomerContact object in Episerver Commerce<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-6153","post","type-post","status-publish","format-standard","hentry","category-episerver-commerce"],"_links":{"self":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts\/6153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/comments?post=6153"}],"version-history":[{"count":4,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts\/6153\/revisions"}],"predecessor-version":[{"id":6157,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/posts\/6153\/revisions\/6157"}],"wp:attachment":[{"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/media?parent=6153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/categories?post=6153"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jonas.kihlsten.se\/blog\/wp-json\/wp\/v2\/tags?post=6153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}