Sitecore Experience Commerce comes with the Sitecore Commerce Engine Project which helps the developer to kick-start their development with already existed plugins. But there is one project which is actually a part of Commerce Engine Solution but not deployed in the any of the Commerce Engine Environments i.e. Sitecore.Commerce.ServiceProxy. Then the question is do we really need this project? So let’s talk about scenarios where we need this project.
Well to demonstrate the use of the Sitecore.Commerce.ServiceProxy I’m gonna take you to the Tax Module that I’m currently working on. This Module is a combination of Engine Code & Storefront code. The Engine Module Consists of the new Entities and Controllers that update the ICart information at the time of purchase. Storefront code will call the Controller to update the Entities and to perform the required operations. But the problem is when you directly calling these controllers from the Storefront you will not be able to make any call to these Entities. This is pretty strange for the beginners who working on the Sitecore Commerce. Now the Question is:
How Does Storefront talk to the Sitecore Commerce?
Well this is where the Sitecore.Commerce.ServiceProxy comes into the Picture.
The Sitecore.Commerce.ServiceProxy acts as a Middle Layer between the Sitecore Commerce Engine Code & Storefront Code. It uses the OData Connected services to create a bridge between Commerce Engine and Storefront.
How does it work?
When you open the Sitecore.Commerce.ServiceProxy project the structure will look like below:
It consists of three main folders i.e. Connected Services. Exceptions and Extensions. The main folder that is responsible for generating the copies of the data for the Commerce Engine Code is Connected Services which consists of CommerceOps and CommerceShops OData connected services. By default, both are pointing to the localhost:5000. In our next blog post, we will guide you step by step for the updating the default host.
Working with ServiceProxy.
After completing your custom plugin code now you need to deploy the code and start creating a component for your storefront. The various step needs to be followed for this.
- Build your Commerce Engine Solution with the custom project reference.
- Deploy the Engine Code to different Engine Roles.
- Add the Sitecore.Commerce.ServiceProxy Project to the Solution.
- In Visual Studio open the Connected Services folder and right-click on the CommerceOps folder then select the Update OData Connected Service option. This will hit the Metadata endpoint and generate the code. Repeat the same for the CommerceShops.
- Deploy the Updated Proxy DLL to your website. Now you can use the Custom Entities to build your component.