We can update profile attributes either using Profile.Update() method or Profile.Update(xmldata, xmlformat) method. The second method is used when we are trying to update using xml data.
This method takes two parameters
1. XML Data
2. Profile XML Format
Commerce server accepts two types of xml formats. This is decide how the
1. ElementCentric
2. AttributeCentric
In the below example I am getting
ProfileContext profileContext = CommerceContext.Current.ProfileSystem;
Profile currency = profileContext.GetProfile(“GeneralInfo.currency_code”, “$”, “Currency”);
currency["GeneralInfo.conversion_factor"].Value = 12;
string xmlData = currency.GetXml(ProfileXmlRetrieve.SchemaAndData, ProfileXmlFormat.ElementCentric);
currency.Update(xmlData, ProfileXmlFormat.ElementCentric);
currency.Update();
Note: In order to make XMLData persist in DB, you should explicitly call Update() method after calling Update(xmldata, xmlformat) method, else XMLData will not be saved to the database.
If your XML data contains only Profile data (not schema) then you will get following error.
“Failed to update profile using specified XML”.
If you like this post, please click on our sponsor advertisement.
