2024 Aug 08 10:06 AM - edited 2024 Aug 08 10:07 AM
Hello SAP experts,
I created the following class in SAP Hybris.
package tr.nttdata.csa.csapromotionengineservices.rule.ruledifinitons.conditions;
public class Task9ProductNameAction extends AbstractRuleExecutableSupport {
private final String SELECT_OPERATOR = "selectOperator";
@Override
public void performAction(RuleActionContext context) {
performActionInternal(context);
}
@Override
protected boolean performActionInternal(RuleActionContext context) {
CartRAO cart = context.getValue(CartRAO.class);
Set<OrderEntryRAO> orderEntries = cart.getEntries();
if (CollectionUtils.isEmpty(orderEntries)) return false;
Task9Operator discountType = (Task9Operator) context.getParameter(SELECT_OPERATOR);
BigDecimal discountAmount = (BigDecimal) context.getParameter("discountAmount");
Optional<OrderEntryRAO> targetEntryOptional = getTargetEntry(orderEntries, discountType);
if (targetEntryOptional.isPresent()){
OrderEntryRAO orderEntry = targetEntryOptional.get();
applyDiscount(context, orderEntry, discountAmount);
return true;
}
return false;
}
private Optional<OrderEntryRAO> getTargetEntry(Set<OrderEntryRAO> orderEntries, Task9Operator discountType){
if (discountType == Task9Operator.LOWEST){
return orderEntries.stream().min(Comparator.comparing(OrderEntryRAO::getTotalPrice));
} else if (discountType == Task9Operator.HIGHEST){
return orderEntries.stream().max(Comparator.comparing(OrderEntryRAO::getTotalPrice));
} else {
return Optional.empty();
}
}
private void applyDiscount(RuleActionContext context, OrderEntryRAO orderEntry, BigDecimal discountAmount){
DiscountRAO discount = new DiscountRAO();
discount.setValue(discountAmount);
discount.setAppliedToQuantity(orderEntry.getQuantity());
RuleEngineResultRAO result = context.getRuleEngineResultRao();
result.getActions().add(discount);
setRAOMetaData(context, discount);
context.insertFacts(discount);
context.scheduleForUpdate(orderEntry, orderEntry.getOrder(), result);
}
}
Then I defined the bean in promotionengineservices-spring.xml file as follows.
<alias name="task9ProductNameAction" alias="task9ProductNameAction"/>
<bean id="task9ProductNameAction" parent="abstractRuleExecutableSupport"
class="tr.nttdata.csa.csapromotionengineservices.rule.evaluation.actions.Task9ProductNameAction">
</bean>
And finally I wrote the following impexes.
INSERT_UPDATE RuleActionDefinition; id[unique = true] ; priority; translatorId ; translatorParameters ; categories(id)
; y_product_name_action ; 350 ; ruleExecutableActionTranslator ; actionId->task9ProductNameAction ; product_discounts
INSERT_UPDATE RuleActionDefinitionParameter; definition(id)[unique = true] ; id[unique = true] ; priority ; type ; value; required[default = true]
; y_product_name_action ; selectOperator ; 150 ; Enum(tr.nttdata.csa.csapromotionengineservices.rule.ruledifinitons.Task9Operator) ; ;
; y_product_name_action ; discountAmount ; 150 ; java.math.BigDecimal ; ;
INSERT_UPDATE RuleActionDefinitionRuleTypeMapping; definition(id)[unique = true] ; ruleType(code)[default = 'PromotionSourceRule'][unique = true]
; y_product_name_action ;
As I expected, all the fields come in the correct format with localization processing, but when I want to publish the promotion, I get the following error.
INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] ************************************* INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] Starting RuleEngineCompilePublishJob INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] ************************************* ERROR [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [DefaultRuleMaintenanceService] The rule compilation finished with errors ERROR [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] Rule Code "task9_promotion": "No bean found for action" INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] ************************************* INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] RuleEngineCompilePublishJob finished with errors INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] *************************************
Can you help me on how to fix this error I have received?
I defined the wrong bean in the spring.xml file. I have solved the problem by looking carefully at the definitions in the official documentation.
<bean id="task9ProductNameRAOAction" parent="abstractRuleExecutableSupport"
class="tr.nttdata.csa.csapromotionengineservices.rule.evaluation.actions.Task9ProductNameAction">
</bean>
<bean id="task9ProductAction" class="de.hybris.platform.ruledefinitions.actions.DefaultRuleExecutableAction">
<property name="raoAction" ref="task9ProductNameRAOAction"/>
</bean>
<bean id="task9ProductNameRAOActionStrategiesMappingMergeDirective" depends-on="promotionActionStrategiesMapping" parent="mapMergeDirective" >
<property name="key" value="task9ProductNameRAOAction"/>
<property name="value" ref="orderEntryAdjustActionStrategy"/>
</bean>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
32 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.