Sitecore Technology MVP & Architect
Sitecore Experience Commerce - Override a promotion benefit action
Sitecore Commerce 9 comes with a set of built-in Promotion Qualifications and Benefits.
In some situations you might need to create custom Qualifications or Benefit actions. Here's a good article on the subject: https://sitecoresmurf.wordpress.com/2019/05/01/create-custom-promotion-benefit-action-with-sitecore-commerce-9/
In other situations you'd rather override/replace an existing Qualification or Benefit to introduce a small change. I was in this situation lately where i wanted to exclude donation products from Percentage based Promotion calculations.
In this blog post, i will walk you through this example and how i did override an OOB Benefit action. (Same process can be applied to qualification actions)
In this example we will be overriding this Benefit action 'CartItemSubtotalPercentOffAction'.
In order to do this we need to follow these steps:
Step 1: First, we need to create a new action class and create an Execute method that would replace the implementation from CartItemSubtotalPercentOffAction**.**
Depending on your requirements, you can also derive from CartItemSubtotalPercentOffAction and override specific methods.
Important: Note here that we use the same EntityIdentifier in order to replace the original implementation.
Step 2: Override GetActionsMetadataBlock used in IGetActionsPipeline to exclude CartItemSubtotalPercentOffAction :
Step 3: Configure IGetActionsPipeline to use the previously created block:
This has been implemented and tested on Sitecore Experience Commerce 9.0.2
As you can see it is quite easy to replace any Qualification or Benefit action by your own implementation by following these 3 easy steps.
P.S: If you intend to do this more than once, it might be useful to create a Policy that contains a list of OOB Actions to replace, and then use that policy in GetActionsMetadataBlock.