我實施了BXGY自定義促銷。 爲了簡化我的情況,讓我們假設在購物車中有X件產品後,您將獲得Y件免費產品。BXGY促銷的多重點燃 - 合格訂單分錄的消費
如果我在購物車中有2 * X合格產品,預期的行爲是獲得2 * Y免費產品。
我的問題是多次推廣該促銷活動。如果我將多次啓動的最大次數設置爲4,則比行動(獲得免費產品)啓用4次,儘管我在購物車中裝有2 * X產品。
所以我的結論是,我需要消耗合格產品(項目與產品)一樣,用戶得到消耗,使他們不能參加資格再推廣免費產品。
我的研究結論是我需要使用(YFreeGift)RAOAction中的條目,但是我需要檢索所有條件產品,並且我不覺得這是一個正確的方式(條件)。
不要任何人知道如何消費排位賽項?
條件翻譯人員BXGY(我有強制性合格產品太多,但不是重要的,這個問題)
public class RuleHeinekenBXGYFQualifyingProductsConditionTranslator implements RuleConditionTranslator
{
@Override
public RuleIrCondition translate(RuleCompilerContext context, RuleConditionData ruleCondition, RuleConditionDefinitionData conditionDefinition) throws RuleCompilerException
{
List<String> mandatoryProducts = (List) getConditionParameterValue(ruleCondition, "mandatoryQualifyingProducts");
List<String> alternativeProducts = (List) getConditionParameterValue(ruleCondition, "alternativeQualifyingProducts");
Integer qualifyingCount = (Integer) getConditionParameterValue(ruleCondition, "qualifyingCount");
if(isEmpty(mandatoryProducts) && isEmpty(alternativeProducts) || qualifyingCount == null || qualifyingCount <= 0)
throw new PromotionConditionParametersValidationException();
String cartRAO = context.generateVariable(CartRAO.class);
List<RuleIrCondition> mandatoryProductsConditions = getMandatoryProductsConditions(context, mandatoryProducts, cartRAO);
List<RuleIrCondition> qualifyingCountCondition = getQualifyingCountCondition(context, qualifyingCount, cartRAO);
RuleIrGroupCondition qualifyingConditions = new RuleIrGroupCondition();
qualifyingConditions.setOperator(RuleIrGroupOperator.AND);
qualifyingConditions.setChildren(listUnion(mandatoryProductsConditions, qualifyingCountCondition));
return qualifyingConditions;
}
private List<RuleIrCondition> getQualifyingCountCondition(RuleCompilerContext context, Integer qualifyingCount, String cartRAO)
{
String qualifyingCountRAO = context.generateVariable(QualifyingCountRAO.class);
String promotionCode = context.getRule().getCode();
return getListOfRuleConditions(
aRuleCondition()
.withModelRAO(qualifyingCountRAO)
.withAttribute("promotionCode")
.withOperator(EQUAL)
.withValue(promotionCode)
.buildAttributeCondition(),
aRuleCondition()
.withModelRAO(qualifyingCountRAO)
.withAttribute("qualifyingCount")
.withOperator(GREATER_THAN_OR_EQUAL)
.withValue(qualifyingCount)
.buildAttributeCondition(),
aRuleCondition()
.withModelRAO(cartRAO)
.withAttribute("qualifyingCounts")
.withOperator(CONTAINS)
.withTargetVariable(qualifyingCountRAO)
.buildAttributeRelationCondition());
}
private List<RuleIrCondition> getMandatoryProductsConditions(RuleCompilerContext context, List<String> mandatoryProducts, String cartRAO)
{
if(isEmpty(mandatoryProducts))
return emptyList();
return getMapOfQualifyingProductsWithQuantities(mandatoryProducts)
.entrySet().stream()
.map(entry -> getMandatoryProductCondition(context, cartRAO, entry.getKey(), entry.getValue()))
.collect(toList());
}
private RuleIrExistsCondition getMandatoryProductCondition(RuleCompilerContext context, String cartRAO, String product, int qualifyingCount)
{
RuleIrLocalVariablesContainer variablesContainer = context.createLocalContainer();
String containsProductRAO = context.generateLocalVariable(variablesContainer, ProductRAO.class);
String containsOrderEntryRAO = context.generateLocalVariable(variablesContainer, OrderEntryRAO.class);
List<RuleIrCondition> listOfConditions = getListOfRuleConditions(
aRuleCondition()
.withModelRAO(containsProductRAO)
.withAttribute("code")
.withOperator(EQUAL)
.withValue(product)
.buildAttributeCondition(),
aRuleCondition()
.withModelRAO(containsOrderEntryRAO)
.withAttribute("product")
.withOperator(EQUAL)
.withTargetVariable(containsProductRAO)
.buildAttributeRelationCondition(),
aRuleCondition()
.withModelRAO(containsOrderEntryRAO)
.withAttribute("quantity")
.withOperator(GREATER_THAN_OR_EQUAL)
.withValue(qualifyingCount)
.buildAttributeCondition(),
aRuleCondition()
.withModelRAO(cartRAO)
.withAttribute("entries")
.withOperator(CONTAINS)
.withTargetVariable(containsOrderEntryRAO)
.buildAttributeRelationCondition());
RuleIrExistsCondition mandatoryProductsExistCondition = new RuleIrExistsCondition();
mandatoryProductsExistCondition.setVariablesContainer(variablesContainer);
mandatoryProductsExistCondition.setChildren(listOfConditions);
return mandatoryProductsExistCondition;
}
}
從閱讀它看起來像Zildyan已經意識到這個屬性的問題。 – Sebastian