Modify Existing Price Calculation Strategy
Out-of-the-box strategies use the same mechanism as custom price calculation strategies. The only difference is where they are stored. They tend to be more generic and configurable, but sometimes they may not be configurable enough. That is why you may decide to extend them on your own. This article explains how to do it.
Strategy Designer gives you ability to use “Strategy Templates” which are based on out-of-the-box Price Setting Accelerator strategies. Please check it out before proceeding, because it may solve your use case in a more user friendly way.
Prerequisites
This article assumes that you know Create and Set up New Price Calculation Strategy.
Where to Find Out-of-the-Box Strategies
All out-of-the-box strategies are stored in the pricefx-logic Git repository in CalculationEnginesLib
. This repository stores our global utilities and we keep them backwards compatible.
CalculationEnginesLib
is deployed automatically when deploying Price Setting Accelerator. If you want to use it on a project without Price Setting Accelerator, it is also possible. You can deploy it independently from Platform Manager Marketplace:
Using Out-of-the-Box Strategy in Custom Strategy
Out-of-the-box strategies follow the same requirements as custom strategies, so each of them will have a calculatePrice(...)
method that returns Map
. All of them also have a detailed explanation about what input parameters are expected and what errors can be thrown. For example, this comes from AdjustmentEngine
:
Usually the most complicated input parameter is going to be setting strategy parameters in StrategyDefinition
PP, but you can check details of what it expects by reading documentation on Calculation Engines. All supported values and expected columns are also defined at the top of the element with the engine’s implementation. For example, AdjustmentEngine
:
This design makes it easy to treat out-of-the-box engines as black boxes. So if you want to add a step before or after, you can manually call the calculatePrice(...)
method from your own custom engine. For example, to do a simple multiplication of a result you could create a custom engine like this:
BigDecimal calculatePrice() {
BigDecimal productCost = 10G
BigDecimal productPercentageAdjustment = 1.05
BigDecimal productAbsoluteAdjustment = null
String calculationMode = "Percentage"
BigDecimal ootbEngineResult = libs.CalculationEnginesLib.AdjustmentEngine.calculatePrice(calculationMode, productCost, productPercentageAdjustment, productAbsoluteAdjustment).result
return [result: ootbEngineResult * 1.05G, message: "OK"]
}
Of course, it can be as simple or as complex as you need, as described in Create and Set up New Price Calculation Strategy, so you can add your own inputs etc.
Using this approach means that all fixes and changes applied to the out-of-the-box engine will be automatically applied to your custom engine when you deploy a newer version of CalculationEnginesLib
.
Modifying Out-of-the-Box Strategy
If you want to reuse the engine and you need to do more “breaking” changes, the recommended way is to create a new custom engine in your own library type logic as described in Create and Set up New Price Calculation Strategy and copy the whole implementation from an existing engine.
Copying the engine is the recommended approach because it assures that your changes will not be overwritten when you decide to upgrade the accelerator or CalculationEnginesLib
.