Price Book migration is also important part, which is missing for now in XC. I will share a few plugins in my blog post series, which will provide a possibility to import/export Price Books via Postman requests, import/export Catalogs, Inventory Sets and Price Books via BizFx interface. It will help editors of Sitecore Commerce who are responsible for these types of tasks and make their lives easier.
The source code: https://github.com/Frog911/Sitecore.Commerce.ImportExport
You have to call Get Token API to receive the token first, and then send this request to XC by clicking on Send and Download option. The Commerce API will generate ZIP file for you, which will contain all the catalogs data.
Let’s decompile DLLs and go through the endpoint implementation. You can find the endpoint implementation in
Sitecore.Commerce.Plugin.Catalog.dll
In the ExportCatalogs action, endpoint extracts Request Body parameters and call ExportCatalogsCommand.
Inside the ExportCatalogCommand it calls IExportCatalogsPipeline with the parameters from the Request.
You can find out more about implementation of IExportCatalogsPipeline in the ConfigureSitecore.cs file.
There is only one block that was registered for this pipeline. It is the ExportCatalogsBlock.
If we navigate to ExportCatalogsBlock we will see that the Export Catalogs feature supports only FULL type of export mode. I guess in the next releases Sitecore Commerce product team will add more supported export modes. I would like to pay attention on the FileCallbackResult class. It provides a possibility to send to the response of a request zip archive.
The Exportfull method calls StreamCatalogItemsToArchivePipeline. This pipeline is responsible for exporting data preparation, which will be stored in the exported JSON file.
Let’s have a closer look into the StreamBulkSellableItemsToArchiveBlock. This block inherits StreamBulkCatalogItemsToArchiveBaseBlock and inside of Run method it invokes StreamCatalogItems method the inherited class.
StreamCatalogItems method retrieves entities from the Commerce Engine by ListName, extorts Localizations and Relationships.
If you extract a downloaded zip file with the exported data, you will see many JSON files there:
The file example of SellableItem.1.json file looks like below:
A similar approach is in the Export Inventory Sets. There is just export of another type of commerce entities. Since Sitecore Commerce does not provide a possibility to export Price Books, I will explain how you can implement your custom import/export endpoints for that. It is also possible to implement import/export for any custom types of commerce entities based on my example, but it will be required to adapt my logic with your custom entities.
I will explain how to implement import/export Price Book endpoints on top of Sitecore Commerce
OOTB import/export pipelines in my next blog post.
Stay tuned!