In part 1 of this series, we highlighted the areas of the Sitecore Commerce engine which can be modified to enable the passing of orders and customers to an ERP system. If you completed the steps in the first article you should now have code “mocking” calls to an ERP. There is, however, nowhere in the system for back-office users to view the fields containing integration status of business entities.
For example, we added a field called “Is integrated” to our “Order” business entity but how will the end user know that the process succeeded without calling the API or searching for the order in the destination ERP system?
The following article will outline the process of modifying the entity views to show the custom fields that were added to the order and customer entities via components in part.
The final result will look something like this…
The example is made up of the following artifacts:-
- A new pipeline block extending the functionality of the “GetEntityView” pipeline.
- A new pipeline registration
Modifying the entity views to display the integration fields in the business tools
We are going to modify the standard process within the system to do the following:-
- A user opens the “Customer and Order Manager” section from within Sitecore, selects the “Orders” tab, then selects an order from the list (Unchanged)
- A call is made to the Sitecore Commerce API for the views relating to the “Order” entity. (Unchanged)
- The “GetEntityView” pipeline is fired (Unchanged)
- The relevant view for the “Order” entity is modified in the pipeline and passed back through to the UI.
- The same process is followed for the “Customer” entity
Open the SDK example solution
- Open the project named “Sitecore.Commerce.Connectors.MYERP.Plugin” that was created in part 1.
- Under “Pipelines\Blocks” add a new class named “ModifyViewsBlock.cs”
- Copy the code below into the class and cleanup as necessary
The code above is called for every request for every entity view but the “if” statements at the top of the block ensure that the code is run at the correct time. After the block validates that is should run correctly, the entity within the call is retrieved and the custom fields are pulled from the plugin components and returned in the view
Registering the new block against the pipeline
- Open the class named “ConfigureSitecore.cs” at the root of your project
- Add the following code to the “ConfigureServices” method…
The full class should now look like this…
Running and debugging the example
Verify your solution, should look like this…
To test that your code is working
- Ensure that you have followed the steps in part 1.
- Start IIS Express by starting the demo solution
- Go to Sitecore and select “Customers and orders manager” from the launchpad
- Select the “Orders” tab
- Select an order from the list that has been processed by the “ReleasedOrdersMinion” (refer to part 1).
- If you have breakpoint added to the new pipeline code it should be hit now.
- The Preview section on the right should contain your custom fields. If you view the details of the order, the other custom fields will be shown.
- Debug the new pipeline block to see how it works.
- Repeat these steps for customers
In other posts, I plan to show the following.
- New API functionality to resend orders to the ERP.