cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable multiple promotion groups for a site in Hybris?

chetanks3005
Discoverer
0 Kudos

I have a requirement where I want 2 promotion groups to be assigned to a BaseSite. Since OOTB allows only one promo group per site, How do I achieve it? Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

saood
Participant
0 Kudos

In the BaseSite --> You will have defaultPromotionGroup, which will apply to that site.

Generally, you can create various campaigns and assign to that promotion but still if you want multiple promotionGroup.

Can you please try this.

Add a collection to the baseSite - promotionGroupList.

Override the below method getPromotionGroups() of DefaultCommerceCartCalculationStrategy and return your promotionGroups inplace of below code


protected Collection<PromotionGroupModel> getPromotionGroups()
{
final Collection<PromotionGroupModel> promotionGroupModels = new ArrayList<PromotionGroupModel>();
if (getBaseSiteService().getCurrentBaseSite() != null
&& getBaseSiteService().getCurrentBaseSite().getDefaultPromotionGroup() != null)
{
promotionGroupModels.add(getBaseSiteService().getCurrentBaseSite().getDefaultPromotionGroup());
}
return promotionGroupModels;
}
chetanks3005
Discoverer
0 Kudos

Thank you.

Answers (1)

Answers (1)

mansurarisoy
Contributor
0 Kudos

This is not possible by default, but luckily PromotionsService's updatePromotions method takes a collection of PromotionGroupModel as its parameter, so I believe this method should work for multiple promotion groups. I did not test it so you need to test it to see whether it works or not.

If it works, what you can do to achieve multiple promotion groups to be assigned to a BaseSite is as follows:

1. Create a many-to-many relation between BaseSite and PromotionGroup

2. Extend DefaultCommerceCartCalculationStrategy with CustomCommerceCalculationStrategy

3. Override getPromotionGroups() method according to your need, it's up to you, some possible scenarios I can think of

  • you can use both defaultPromotionGroup and promotionGroups you defined and merge them in the collection
  • you can only use promotionGroups
  • you can use promotionGroups but defaultPromotion as fallback if no promotionGroups define

4. Define spring bean for your custom strategy and alias for commerceCartCalculationStrategy

<alias alias="commerceCartCalculationStrategy" name="customCommerceCartCalculationStrategy"/>
<bean id="customCommerceCartCalculationStrategy" parent="defaultCommerceCartCalculationStrategy"
class="com.customextension.order.impl.CustomCommerceCartCalculationStrategy">
</bean>

Hope this helps,