cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Exclude specific products from all kind of promotions

0 Likes
2,873

Hi,

How can we exclude specific products from all promotions in hybris.

We need this restriction in hybris 6.3 B2C using promotion engine.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Likes

Create a classification category called 'Fresh Arrivals'. Add products in this category and put a category restriction, so any product that you wish to be not included in promotion, just add it to 'Fresh Arrivals' classification category. If a week later you realise that you now wish to include this product in promotion, just remove it from the classification category.

eatamanenco
Explorer
0 Likes

Hi,

I had similar requirements and proceeded in the following way:

Added new attribute in Product model

 <attribute qualifier="excludedFromPromotions" type="boolean">
     <description>Indicates that product will be excluded from global discount calculations</description>
     <defaultvalue>false</defaultvalue>
     <persistence type="property"/>
 </attribute>


Added new attribute in bean ProductRao

 <bean class="de.hybris.platform.ruleengineservices.rao.ProductRAO">
     <property name="excluded" type="boolean"/>
 </bean>

Added two populators

 public class MyProductRaoExcludedPopulator implements Populator<ProductModel, ProductRAO>
 {
     @Override
     public void populate(final ProductModel source, final ProductRAO target)
     {
         target.setExcluded(source.isExcludedFromPromotions());
     }
 }
 
 
 public class MyCartRaoPopulator extends CartRaoPopulator
 {
     @Override
     public void populate(final AbstractOrderModel source, final CartRAO target)
     {
         super.populate(source, target);
 
         target.setEntries(filterEntries(target.getEntries()));
     }
 
     private Set<OrderEntryRAO> filterEntries(final Set<OrderEntryRAO> entries)
     {
         return entries.stream()
                 .filter(entry -> !entry.getProduct().isExcluded())
                 .collect(Collectors.toSet());
     }
 }

Changed bean declarations

 <bean id="myProductRaoExcludedPopulator" class="com.my.core.promotion.populator.myProductRaoExcludedPopulator"/>
 
 <bean id="mypProductRaoConverter" parent="defaultProductRaoConverter">
     <property name="populators">
         <list>
             <ref bean="productRaoPopulator"/>
             <ref bean="myProductRaoExcludedPopulator"/>
         </list>
     </property>
 </bean>
 
 <alias name="myProductRaoConverter" alias="productRaoConverter"/>
 
 <alias name="myCartRaoPopulator" alias="cartRaoPopulator" />
 <bean id="myCartRaoPopulator" class="com.my.core.promotion.populator.MyCartRaoPopulator" parent="defaultCartRaoPopulator"/>


Overrode method from DefaultCalculationService in MyCalculationService: protected double calculateDiscountValues(final AbstractOrderModel order, final boolean recalculate)

copied code from parent method and made there small adjustment

 ...
 final double discountablePrice = calculateDiscountablePrice(order)
 ...

added method in MyCalculationService private double calculateDiscountablePrice(final AbstractOrderModel order) and copied code from parent DefaultCalculationService::calculateSubtotal

made adjustments, where the main one was

 ...
 for (final AbstractOrderEntryModel entry : entries)
        {
            if (!entry.getProduct().isExcludedFromPromotions())
            {
 ...

Do not forget to adjust spring beans for that (most probable you have already own CalculationService).

And it is working.

Former Member
0 Likes

Thanks for sharing. However, this allows controlling what products are excluded from outside the promotion - say backoffice, directly marking a product as excluded.

What if we want to set excluding products from within promotions? So a product could be excluded from one promotion whereas it is included in others. How would you add such an exclusion in the condition and make it available in the action? Any suggestions.

Thanks.

Former Member
0 Likes

You need to create a new promotion condition to ignore the products based on an attribute and add the condition to all promotion templates. Whenever a promotion rule is created using the template, this condition will be added by default.

Former Member
0 Likes

In my opinion, adding a new condition is not sufficient. You should add a new "action" too.

if your discount simply says "10% on everything", and you want to exclude some products or categories, then you don't need any "condition".

Former Member
0 Likes

The condition works on an attribute at product level, if you want to give 10% on everything, you can simply remove the condition from the promotion rule instance.

Former Member
0 Likes

Hallo

Did you find a solution for that ? We have similar problem.. Thanks

Nicolo