How We Add New Rule Condition Parameter

and so on…
$lang = en

INSERT_UPDATE RuleConditionDefinition; id[unique = true] ; name[lang = $lang] ; priority; breadcrumb[lang = $lang] ; allowsChildren; translatorId ; translatorParameters; categories(id)
; y_category_total_quantity ; Category total Quantity ; 700 ; Category {categories} total {operator} {quantity} ; false ; ruleCategoryTotalQuantityConditionTranslator ; ; general

INSERT_UPDATE RuleConditionDefinitionParameter; definition(id)[unique = true]; id[unique = true]; priority; name[lang = $lang] ; description[lang = $lang] ; type ; value ; required[default = true]
; y_category_total_quantity ; brands ; 1150 ; Brands ; List of brands to be evaluated ; List(ItemType(Category)) ; ; false;
RuleParameterData brandsParameter = conditionParameters.get("brands");if (verifyAllPresent(operatorParameter, quantityParameter, categoriesParameter,brandsParameter)) {//add brands parameter variable for verifyAllPresent
List<String> brandCodes = brandsParameter.getValue();//get brands
......//add this method to check product that is contains the brand code or not
RuleIrAttributeCondition createBrandCodeCondition(RuleCompilerContext context, List<String> brands) {
return RuleIrAttributeConditionBuilder.newAttributeConditionFor(context.generateVariable(BrandsRAO.class))
.withAttribute("code")
.withOperator(RuleIrAttributeOperator.IN)
.withValue(brands)
.build();
}
//..and we need to add product brands relation condition
RuleIrAttributeRelCondition createBrandProductRelation(RuleCompilerContext context) {
return RuleIrAttributeRelConditionBuilder.newAttributeRelationConditionFor(context.generateVariable(ProductRAO.class))
.withAttribute("brands")
.withOperator(RuleIrAttributeOperator.CONTAINS) .withTargetVariable(context.generateVariable(BrandsRAO.class))
.build();
}
<bean class="de.hybris.platform.ruleengineservices.rao.BrandsRAO">
<property name="code" type="String" equals="true"/>
</bean>
<alias name="defaultBrandsRaoConverter" alias="brandsRaoConverter" />
<bean id="defaultBrandsRaoConverter" parent="abstractPopulatingConverter">
<property name="targetClass" value="de.hybris.platform.ruleengineservices.rao.BrandsRAO" />
<property name="populators">
<list>
<ref bean="brandsRaoPopulator"/>
</list>
</property>
</bean>

<alias name="defaultBrandsRaoPopulator" alias="brandsRaoPopulator" />
<bean id="defaultBrandsRaoPopulator"
class="tr.com.karahan.ruleengineservices.populators.BrandsRaoPopulator">
</bean>
<bean class="de.hybris.platform.ruleengineservices.rao.ProductRAO"
extends="de.hybris.platform.ruleengineservices.rao.AbstractActionedRAO">
<property name="brands" type="java.util.Set&lt;de.hybris.platform.ruleengineservices.rao.BrandsRAO>" />
</bean>
<alias name="defaultKarahanProductRaoPopulator" alias="productRaoPopulator" />
<bean id="defaultKarahanProductRaoPopulator" class="tr.com.karahan.ruleengineservices.populators.KarahanProductRaoPopulator" parent="defaultProductRaoPopulator">
<property name="brandsConverter" ref="brandsRaoConverter" /> <property name="karahanCategoryService" ref="karahanCategoryService"/>
</bean>
//----IMPORTANT-----//
//--add brands provider to provide the facts required to evaluate rules and apply actions
<alias name="defaultBrandsRaoProvider" alias="brandsRaoProvider"/>
<bean id="defaultBrandsRaoProvider" class="tr.com.karahan.ruleengineservices.rao.provider.BrandsRaoProvider"/>
//-cart provider extractors run our brandsraoprovider with this line
<bean depends-on="cartRAOProviderExtractors" parent="listMergeDirective">
<property name="add" ref="brandsRaoProvider"/>
</bean>
public class KarahanProductRaoPopulator extends ProductRaoPopulator {

private KarahanCategoryService karahanCategoryService;
private Converter<CategoryModel, BrandsRAO> brandsConverter;

@Override
public void populate(ProductModel source, ProductRAO target) {
super.populate(source, target);
CategoryModel brandModel = karahanCategoryService.getBrand(source);
HashSet<BrandsRAO> brandsCats = new HashSet(Collections.singleton(getBrandsConverter().convert(brandModel)));
target.setBrands(brandsCats);
}

public Converter<CategoryModel, BrandsRAO> getBrandsConverter() {
return brandsConverter;
}

public void setBrandsConverter(Converter<CategoryModel, BrandsRAO> brandsConverter) {
this.brandsConverter = brandsConverter;
}

public KarahanCategoryService getKarahanCategoryService() {
return karahanCategoryService;
}

public void setKarahanCategoryService(KarahanCategoryService karahanCategoryService) {
this.karahanCategoryService = karahanCategoryService;
}
}
public class BrandsRaoPopulator implements Populator<CategoryModel, BrandsRAO> {

@Override
public void populate(CategoryModel source, BrandsRAO target) throws ConversionException {
target.setCode(source.getCode());
}
}
public class BrandsRaoProvider implements RAOFactsExtractor {

private static final String EXPAND_BRANDS_DEFINITION = "EXPAND_BRANDS";

@Override
public Set expandFact(Object fact) {
Preconditions.checkArgument(fact instanceof CartRAO, "CartRAO type is expected here");
Set<Object> facts = new HashSet<>();
CartRAO cartRAO = (CartRAO)fact;
if (CollectionUtils.isNotEmpty(cartRAO.getEntries())) {
for(OrderEntryRAO orderEntryRAO : cartRAO.getEntries()){
ProductRAO productRAO = orderEntryRAO.getProduct();
if(Objects.nonNull(productRAO)) {
facts.addAll(productRAO.getBrands());
}
}
}
return facts;
}

@Override
public String getTriggeringOption() {
return EXPAND_BRANDS_DEFINITION;
}

@Override
public boolean isMinOption() {
return false;
}

@Override
public boolean isDefault() {
return true;
}
}

SAP Hybris/Java Spring/PHP Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Competitive Programming: Progress and Insights as a Beginner

7 Common Scrum Myths

Coding Tutor Tip-6-Is Coding For You?

Using Docker Build Strategy on an Enterprise Kubernetes and OpenShift Cluster

Guide to Becoming a Full Stack Developer — Part 1

Opacity — A Flutter Widget — WalkingTree Technologies

Welcome To the Dark (mode).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mehmet Karahan

Mehmet Karahan

SAP Hybris/Java Spring/PHP Developer

More from Medium

Cross-platform [Technical Term]

Configure Tailwind CSS for Vanilla JS with JIT in 10 Easy Steps

All About Azure & Steps to Create Website Using Visual Studio

WHAT SOFTWARE TO USE AS AN ARCHITECTURE STUDENT?