Vulnerability in EPiServer.Forms
Im currently trying to do a integration through the new IContent API i Commerce 7.5 but I cant get it to keep the data saved on the frontend when I publish the imported data through code.
My setup is this
I have a ContentNode with the type Category
Category has a Description and a DisplayName
I go to the frontend and type in some content i the description without publishing the change.
After that I run the integration using the IContentRepository
The code looks like the following:
var category = (Category)_contentRepository.Get<Category>(_referenceConverter.GetContentLink(code, CatalogContentType.CatalogNode).ToReferenceWithoutVersion(), new LanguageSelector(language.Name)).CreateWritableClone();
category.DisplayName = "I Have been updated!!";
_contentRepository.Save(category, SaveAction.Publish, AccessLevel.NoAccess);
After running the code i can see the DisplayName has been updated but I lost the content I typed into the Description.
How do I get it to keep both changes and publish both?
ahh found the issue, I had to use the IContentVersionRepository to get the current draft
here is the updated code
var categoryCode = "CATEGORY1234"
var link = _referenceConverter.GetContentLink(categoryCode , CatalogContentType.CatalogNode); var draft = _versionRepository.LoadCommonDraft(link, language.Name);
var category = (Category)_contentRepository.Get<Category>(draft.ContentLink).CreateWritableClone()
Hope it helps somebody else one day :-)
It helped me. Thanks for sharing!