Sitecore OrderCloud: How to use Me and My Stuff

sitecore-techtalks

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.

Sitecore Commerce 9: Import Price Books

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.

Sitecore Commerce 9: Import Price Books

Now we have to create custom argument. ImportPriceBooksArgument will be using by custom pipeline to share some data through the pipeline blocks.

Sitecore Commerce 9: Import Price Books

Creating pipeline interface and implementing it:

Sitecore Commerce 9: Import Price Books

Sitecore Commerce 9: Import Price Books

Let’s update the ConfigureSitecore.cs file with some pipeline registrations.

Sitecore Commerce 9: Import Price Books

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.

Sitecore Commerce 9: Import Price Books

 

Sitecore Commerce 9: Import Price Books

 

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!