我已经实施了BXGY自定义促销。
为了简化我的案例,假设您的购物车中有X个产品,您将获得Y个免费产品。

如果我的购物车中有2 * X个合格产品,则预期的行为是获得2 * Y个免费产品。

我的问题是该晋升的多次射击。如果我将多重射击的最大次数设置为4,则尽管我的购物车中有2 * X个产品,但动作(获取免费产品)却被激活了4次。

所以我的结论是,我需要消费合格的产品(与该产品有关的条目),例如消费用户获得的免费产品,这样他们就无法参与其他促销的资格。

我的研究结论是,我需要使用(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;
    }
}

最佳答案

规则引擎为您提供了一种机制来配置限制
  规则可以触发“操作项”的次数。
  
  最大规则执行次数使您可以控制最大数量的
  只要有条件,就可以执行规则操作
  被满足。对于所有现成的促销活动,此操作的价值
  属性应设置为1。


查看RuleConfigurationRRD属性。

取自help.hybris.com。

10-08 00:10