on ‎2018 Jan 30 9:56 PM
Hi,
How can we exclude specific products from all promotions in hybris.
We need this restriction in hybris 6.3 B2C using promotion engine.
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hallo
Did you find a solution for that ? We have similar problem.. Thanks
Nicolo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.