Question & Answer
How to apply promotions based on priority rather then promotion-group order *|* -7B511C81482106DE85257837005D2C8F- *|*
How to apply promotions based on priority rather then promotion-group order?
The client wants promotions to be applied strictly based on the priority as otherwise they may end up giving more discount amount. So the question is; can this default order be changed some how for example is there a configuration which can be changed so that promotions are applied based on priority and not promotion-group order?
Here is an example:
If you have 2 promotions in the system:
a) All orders over $20 gets $5 off. Priority for this promotion is 150
b) All products in category "A" gets 10% off. Priority for this promotion is 100
If you add an item (worth $50) from category "A". Now promotions are applied in order of "b" and then "a". So final amounts comes to $40 (For example: $50 - 10% = $45 $45 - $5 = $40)
However the business wants the promotions applied in order of a and then b (based on the priority). Per business the final amount should be $40.50 (For example: $50 - $5 = $45 $45 - 10% = $40.50)
Promotion groups serve the following two purposes:
1- All of the promotions within a group share a common set of promotion policies.
2- Promotion groups are one factor that determines the order in which the promotion engine evaluates promotions during the shopping flow to determine whether the promotion applies to the current shopping cart or order.
By default promotions are evaluated according to their promotion group in the following order:
The out of the box promotions are evaluated according to the order of promotion groups and the priority value if they are within the same promotion group The order level promotion (a) will be evaluated/applied after product level promotions (b). If you only want to evaluate based on priority value and ignore the order of promotion groups.
You will need to override the comparePromotionPriority () method of the PromotionExecutionSequenceBuilder that is used with the PromotionEngine.
* Compares the priority of two promotions
* @param promo1
* The first promotion.
* @param promo2
* The second promotion.
* @param context
* The current promotion context
* @return >0 when promo1 has precedence over promo2 =0
promo1 and promo2
* have the same priority <0 promo2 takes
precedence over promo1
protected int comparePromotionPriority(Promotion promo1
Promotion promo2 PromotionContext context)
12 October 2021