New simple batch saving API for Commerce
In Commerce 13.8, we introduced a new, simple batch saving API for catalog content. If you want to try it out, look into new extension method of IContentRepository, resides in
EPiServer.Commerce.Extensions. There is a new method called "Publish", which allows you to publish multiple catalog content at once. This is an example of updating all language versions of a content.
var languageBranches = ContentRepository.GetLanguageBranches<VariationContent>(content.ContentLink);
var list = new List<VariationContent>();
foreach (var languageBranch in languageBranches)
{
var writable = languageBranch.CreateWritableClone<VariationContent>();
writable.Name += "updated";
writable.DisplayName += "updated";
list.Add(writable);
}
ContentRepository.Publish(list);
Publish can take language versions of a content, multiple content with same language, or a combination of both.
It's important to keep this mind that this method skips certain things for the optimal speed. As in the remarks, "This method bypasses the content publishing pipeline and therefore does not validate for error, nor fire content level events, nor handle versions. It does not create new versions, but commits data in the contents to the published versions.". The low level events, however will still be fired.
You might ask what would be the use cases of the new API. Well, this new API is simple, and it acts as a shell for Catalog import export. You can achive almost the same result (with somewhat better performance) with CatalogImportExport. However, the big drawback of CatalogImportExport is that you need to have the XML - either from a PIM connector, or build it yourself, which is not the most hassle-free task in the world. If you already have code to build your catalog content instances, you can use this API to "publish" your change.
A new improvement which allows you to sync draft is coming in Commerce 13.9. A new overload which takes a PublishAction (new enum) parameter is added, if you choose PublishAction.SyncDraft, it will sync the changes to the versions, so you can see changes there as well.
Note that this API is still marked as BETA. As usual, BETA means tested, but we reserve the right to make changes to the APIs without notice/major versions. That also means your feedback and suggestions can be implemented sooner than usual.
Comments