In my previous blog post, I explained how to implement export Price Books feature.
Now I am going to explain how to implement import Price Books feature.
Source code you can find here: https://github.com/Frog911/Sitecore.Commerce.ImportExport
First, let’s start from the endpoint implementation.
ImportPriceBook action will support some parameters like importFile, errorThreshold, mode and publishEntities. We have to implement ImportPriceBooksCommand, which we will invoke with the ExecuteLongRunningCommand operation. When we will call our custom endpoint for the import process, it can take quite a lot time. It depends how huge is our Price Books will be.
In our case, ExecuteLongRunningCommand will return an object, which will contain TaskId. Sitecore Commerce provides an endpoint to track the task status.
The implementation of ImportPriceBooksCommand should look like below.
Now we have to create custom argument. ImportPriceBooksArgument will be using by custom pipeline to share some data through the pipeline blocks.
Creating pipeline interface and implementing it:
Let’s update the ConfigureSitecore.cs file with some pipeline registrations.
The implementation of blocks you can find in my GitHub repo with I mentioned above.
Now everything is ready for testing. Let’s try to call ImportPriceBooks endpoint from Postman.
As you can see, Price Books were imported successfully.
In the next blog post, I will explain how to extend BizFx interface to support import/export features.
Stay tuned!