cancel
Showing results for 
Search instead for 
Did you mean: 

Compare two fields in one product in promotion condition

0 Kudos

Hello, I'm creating custom condition in new promotion engine, it should compare two fields from one product. They are added to ProductRAO and populated correctly, but during adding product to basket error is thrown:

 java.lang.RuntimeException: Error evaluating constraint 'recommendedRetailPrice > $v4.europe1Prices' in [Rule "rule_a0b0a74664f5427f91b38749353de7f1_query" in de/hybris/platform/droolsruleenginesales testRuleMedia.drl]


My translator:

 public class SalePriceTranslator extends AbstractRuleConditionTranslator
 {
     public static final String RECOMMENDED_RETAIL_PRICE = "recommendedRetailPrice";
     public static final String WEB_PRICE = "europe1Prices";
 
     @Override
     public RuleIrCondition translate(RuleCompilerContext ruleCompilerContext, RuleConditionData ruleConditionData,
             RuleConditionDefinitionData ruleConditionDefinitionData)
     {
         final String productRaoVariable = ruleCompilerContext.generateVariable(ProductRAO.class);
 
         final List<RuleIrCondition> irConditions = new ArrayList<>();
         final RuleIrTypeCondition irProductCondition = new RuleIrTypeCondition();
         irProductCondition.setVariable(productRaoVariable);
 
         final RuleIrAttributeRelCondition irRrpWebRel = new RuleIrAttributeRelCondition();
         irRrpWebRel.setVariable(productRaoVariable);
         irRrpWebRel.setAttribute(RECOMMENDED_RETAIL_PRICE);
         irRrpWebRel.setOperator(RuleIrAttributeOperator.GREATER_THAN);
         irRrpWebRel.setTargetVariable(productRaoVariable);
         irRrpWebRel.setTargetAttribute(WEB_PRICE);
 
         irConditions.add(irProductCondition);
         irConditions.add(irRrpWebRel);
 
         final RuleIrGroupCondition irSalePriceCondition = new RuleIrGroupCondition();
         irSalePriceCondition.setOperator(RuleIrGroupOperator.AND);
         irSalePriceCondition.setChildren(irConditions);
         return irSalePriceCondition;
     }
 
 }


Is it correct way of comparing fields, or I'm doing something wrong? Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member1320010
Participant
0 Kudos

I have not tried this particular scenario yet however i assume RuleIrAttributeRelCondition is not the correct one to use here and should be RuleIrAttributeCondition

 RuleIrAttributeCondition irProductCondition = new RuleIrAttributeCondition();
     irProductCondition.setVariable(productRaoVariable);
     irProductCondition.setAttribute(RECOMMENDED_RETAIL_PRICE);
     irProductCondition.setOperator(RuleIrAttributeOperator. GREATER_THAN);
     irProductCondition.setValue(WEB_PRICE);