Extend Sitecore 9 Commerce API with custom commands

Goal > Our plan is to create a custom command and call that command through postman.

Let’s start. Task Requirements > My manager asked me to add a component in the cart line item.

I have created a project in our plugin solution. By the way, we have completed different solution for plugin and our MVC project. My project name is “Products.Plugin.Cart” which is added to “Sitecore.Commerce.Engine” already.

Step 1 > Create custom component.

I have a folder called Components in my custom plugin project. This ProductId and Unitprice, we are going to send their party. We have no other option except adding them in the Cart line item.

Please check the code snippet for my custom component. You can see in the below code that I have inherited from “Component” which is very important to do.

Step 2 > Create command.

Now, we are creating custom command. Please check the code below –. Please notice that I have inherited from CommerceCommand

Step 3 > Create Controller

The base class is CommerceController

Step 4 > Register OData API method

We also need to register our new OData API method by creating custom pipeline block.

Step 5 > test

Now. You should see this component available in all cartline component. Code snippet to get the