/
Recipe: Custom Strategies

Recipe: Custom Strategies

This recipe is outdated

Business Scenario

If the built-in strategy engines do not meet your requirements, you can easily “plug in” a custom strategy engine to be used in the Price Setting Package. In this section you will learn how to build your own strategy engine and connect it to the Price Setting Package. The custom engine can be used the same way as the built-in strategies. There is no difference in how they are used in PL/LPG afterwards.

In addition, you will learn how to wrap a built-in engine with your custom engine. This can be good when you want to use the results of the built-in engine and perform some additional operations.

As a business example, we use “Capped Price Increase”. It is a price increase strategy with some fixed limit, for example: Actual Price + 5%, but not more than 50 € of an absolute price increase. In this use case only relative price increase is supported because capped increase does not make sense with absolute increase.

Accelerator Package as Solution

Accelerator

Accelerate Price Setting Package

Mandatory Data

Deployed and configured Price Setting Accelerator Package

Deployment

Deploy the Accelerate Price Setting Package through PlatformManager. This will also deploy the standard pre-configuration which will make it easier to get started.

Create Library Function

You need to create a library function that can be used as a custom strategy engine. You should add it to your own Groovy Library separately from the built-in engines.

The library needs to follow very simple format.

BigDecimal sampleEngine(BigDecimal cost){ return cost + 5 }

In this use case we want to create PriceIncrease Strategy with relative price increase and absolute maximum increase.

So, in this example, we create a Groovy library “CustomEngines”. In this library, we create an element “CappedPriceIncrease”. It has the following parameters:

  • basePrice – Actual valid price for the SKU

  • productAdjustment – Price increase for the SKU

BigDecimal calculatePrice(BigDecimal basePrice, BigDecimal productAdjustment) { }

To set up this strategy in the Strategy Definition PP:

  • Create an entry for “CappedPriceIncrease”.

  • Set up the same parameters as in “normal” PriceIncrease Strategy.

    • BASE_PRICE – Actual price of the SKU

    • PRICE_INCREASE – Price increase, looked up in the PriceIncrease PP in %

The defined parameters will be passed in this order to the custom engine.

Now we want to use the out-of-the-box Price Increase Engine. So we just call it from our custom engine:

BigDecimal calculatePrice(BigDecimal basePrice, BigDecimal productAdjustment) { strategyConfigFromPP = ["Calculation Mode" : "Percentage"] def lib = libs.PriceListManagement BigDecimal productAbsoluteAdjustment = 0 def increasedPrice = lib.AdjustmentEngine.calculatePrice(basePrice, productAdjustment, productAbsoluteAdjustment strategyConfigFromPP) return increasedPrice }

 

Now, we want to limit the maximum price increase to a fixed value:

 

In a last step, we want to make the maxIncrease a parameter.

We can use the PriceIncrease PP (the same that is used to store PriceIncrease % in the out-of-the-box functionality). We just can use attribute2 for this. So the setup can look like this:

 

Once the PP table is adjusted, we can inject it in the price calculation dispatcher. First we need this code to look up the maxIncrease parameter:

 

To inject it, we have the element “AdditionalCalculatorParameters” in the PL Logic (IndependentPriceListLogic & DependentPriceListLogic). It looks like this:

We just add it to the provided map:

After this, our “MAX_INCREASE” is available as a parameter in the calculation dispatcher and it can be passed to the engine:

The last thing to do is to add this to our custom engine:

Related content

Create and Set up New Price Calculation Strategy
Create and Set up New Price Calculation Strategy
More like this
Define New Pricing Strategy
Define New Pricing Strategy
More like this