on 2020 Jun 17 7:36 AM
I am following Hybris 6.7 documentation's trail to create a simple custom promotion.
My goal is to add one integer field into UserRao and create a simple condition but use an already existing action like "fixed discount on the cart".
After building and launching the server using the following coding I can see the condition and I can create a promotion using that, but it doesn't get triggered. Other OOTB promotions are working fine but this one doesn't work at all.
Here is what I have done so far:
1. add int field to UserRao
<bean class="de.hybris.platform.ruleengineservices.rao.UserRAO">
<property name="cPoints" type="java.lang.Integer"/>
</bean>
2. Create java populator
public class CustomerPointRaoPopulator implements Populator<UserModel, UserRAO>
{
@Override
public void populate(final UserModel source, final UserRAO target) throws ConversionException
{
if (source instanceof CustomerModel)
{
final CustomerModel customerModel = (CustomerModel) source;
target.setCPoints(customerModel.getCPoints());
}
}
}
3. Add it to spring beans
<alias name="defaultCustomerPointsUserRaoPopulator" alias="customerPointsUserRaoPopulator" />
<bean id="defaultCustomerPointsUserRaoPopulator" class="de.hybris.promotionenginetrail.converters.populator.CustomerPointRaoPopulator"/>
<bean parent="modifyPopulatorList">
<property name="list" ref="userRaoConverter" />
<property name="add" ref="customerPointsUserRaoPopulator" />
</bean>
4. Create a provider and define its spring bean
public class CustomerPointRaoExtractor implements RAOFactsExtractor
{
public static final String EXPAND_CUSTOMER_POINTS = "EXPAND_CUSTOMER_POINTS";
@Override
public Set<?> expandFact(final Object fact)
{
checkArgument(fact instanceof CartRAO, "CartRAO type is expected here)");
final Set<Object> facts = new HashSet<>();
final CartRAO cartRAO = (CartRAO) fact;
if (nonNull(cartRAO.getUser()))
{
facts.add(cartRAO.getUser().getCPoints());
}
return facts;
}
@Override
public String getTriggeringOption()
{
return EXPAND_CUSTOMER_POINTS;
}
@Override
public boolean isMinOption()
{
return false;
}
@Override
public boolean isDefault()
{
return true;
}
}
<alias name="defaultCustomerPointsRaoExtractor" alias="customerPointsRaoExtractor" />
<bean id="defaultCustomerPointsRaoExtractor" class="de.hybris.promotionenginetrail.rao.providers.impl.CustomerPointRaoExtractor" />
<bean depends-on="cartRAOProviderExtractors" parent="listMergeDirective">
<property name="add" ref="customerPointsRaoExtractor" />
</bean>
5. Create and define a translator bean
<alias alias="ruleLoyaltyPointsTranslator" name="defaultRuleLoyaltyPointsTranslator" />
<bean id="defaultRuleLoyaltyPointsTranslator" class="de.hybris.promotionenginetrail.definitions.conditions.RuleCustomerLoyaltyPointsTranslator">
<property name="consumptionEnabled" value="true"/>
</bean>
6. run Impex
#condition definition
INSERT_UPDATE RuleConditionDefinition;id[unique=true];name[lang=$lang];priority;breadcrumb[lang=$lang];allowsChildren;translatorId;translatorParameters;categories(id)
;customer_loyalty_point;Loyalty Points;200;Customer has earned Loyalty Points in AR;false;ruleLoyaltyPointsTranslator;;customer
INSERT_UPDATE RuleConditionDefinitionParameter;definition(id)[unique=true];id[unique=true];priority;type;value;required[default=true];validators;filters;defaultEditor
;customer_loyalty_point;operator;1320;Enum(de.hybris.platform.ruledefinitions.AmountOperator);"""GREATER_THAN_OR_EQUAL""";;;
;customer_loyalty_point;quantity;1220;java.lang.Integer;1;;rulePositiveNumberParameterValidator;
INSERT_UPDATE RuleConditionDefinitionRuleTypeMapping;definition(id)[unique=true];ruleType(code)[default=PromotionSourceRule][unique=true]
;customer_loyalty_point
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.