java - BXGY促销多重火爆-合格订单消耗

标签 java sap-commerce-cloud promotions

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

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

我的问题是多次触发该促销 Activity 。如果我将多重发射的最大计数设置为 4,则尽管我的购物车中有 2*X 个产品,但操作(获取免费产品)会被激活 4 次。

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

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

最佳答案

Rule Engine provides a mechanism for you to configure a limit on the number of times a rule can trigger Action Items.

The maximum rule executions allow you to control the maximum number of times the action for a rule can be executed, as long as the conditions are met. For all out-of-the-box promotions actions, the value of this attribute should be set to one.

查看 RuleConfigurationRRD 属性。

取自help.hybris.com。

关于java - BXGY促销多重火爆-合格订单消耗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44238254/

相关文章:

java - 使用 xpath 操作 json 文件的有效方法?

java - 避免将 CallbackHandler 与 cxf ws-security 和 spring 一起使用

sap-commerce-cloud - 通过插件更改 Hybris 上的 Logo

java - 当使用另一个按钮 - HYBRIS 进行操作时,如何禁用后台中的按钮?

java - 防止 Redshift SQL 注入(inject)

JavaFX widthProperty 不刷新

java - SAP Hybris 是否使用 Resful 服务,或者也可以使用 SOAP?我们可以在 UI 中使用 AngularJS 吗?

Java 垃圾收集器 : top object classes promoted (by size)?

c - C99 标准中的默认参数提升

magento - Magento 中的促销规则