Sitecore Commerce - Web project notification regarding order completion
on 17. August 2020. in category Sitecore
When order is completed in the engine project we wanted it to be followed by some business logic in a web project. Order undergoes status like pending, released, problem, completed, the intention was to catch it when order is completed and payment settled in the engine project and to alert the web project as the result. Order is completed after Release Minion is finished and after the block MoveReleasedOrderBlock, when order changes status from released to completed. So we created new plugin on engine project and added our custom block NotifyOrderCompletedBlock after that one:
NotifyOrderCompletedBlock is a simple http request to a web project where we are sending order as a json object. We used IHttpClientFactory.
Next step is implementing observer pattern in the web project. When changes happen to a class that we are tracking(subject), it alerts all other classes which are subscribed to it and business logic happens in subscribers. Interface and the class we are tracking:
Subscriber class:
We also need to register container for dependency injection:
Endpoint for web project is:
We wanted to subscribe class when application starts. In Foundation/Commerce/code/Pipelines we added CommerceInitializeProcessor.cs file:
And in Foundation\Commerce\code\App_config\Include\Foundation\Commerce\ we added z.Foundation.Commerce.CommerceInitializeProcessor.config: