当前位置: 首页>>代码示例>>Java>>正文


Java CartItemModifyException类代码示例

本文整理汇总了Java中org.ofbiz.order.shoppingcart.CartItemModifyException的典型用法代码示例。如果您正苦于以下问题:Java CartItemModifyException类的具体用法?Java CartItemModifyException怎么用?Java CartItemModifyException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CartItemModifyException类属于org.ofbiz.order.shoppingcart包,在下文中一共展示了CartItemModifyException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runProductPromoRules

import org.ofbiz.order.shoppingcart.CartItemModifyException; //导入依赖的package包/类
protected static boolean runProductPromoRules(ShoppingCart cart, Long useLimit, boolean requireCode, String productPromoCodeId, Long codeUseLimit, long maxUseLimit,
    GenericValue productPromo, List<GenericValue> productPromoRules, LocalDispatcher dispatcher, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException, UseLimitException {
    boolean cartChanged = false;
    Map<ShoppingCartItem,BigDecimal> usageInfoMap = prepareProductUsageInfoMap(cart);
    String productPromoId = productPromo.getString("productPromoId");
    while ((useLimit == null || useLimit.longValue() > cart.getProductPromoUseCount(productPromoId)) &&
            (!requireCode || UtilValidate.isNotEmpty(productPromoCodeId)) &&
            (codeUseLimit == null || codeUseLimit.longValue() > cart.getProductPromoCodeUse(productPromoCodeId))) {
        boolean promoUsed = false;
        BigDecimal totalDiscountAmount = BigDecimal.ZERO;
        BigDecimal quantityLeftInActions = BigDecimal.ZERO;

        Iterator<GenericValue> promoRulesIter = productPromoRules.iterator();
        while (promoRulesIter != null && promoRulesIter.hasNext()) {
            GenericValue productPromoRule = promoRulesIter.next();

            // if apply then performActions when no conditions are false, so default to true
            boolean performActions = true;

            // loop through conditions for rule, if any false, set allConditionsTrue to false
            List<GenericValue> productPromoConds = EntityQuery.use(delegator).from("ProductPromoCond").where("productPromoId", productPromo.get("productPromoId")).orderBy("productPromoCondSeqId").cache(true).queryList();
            productPromoConds = EntityUtil.filterByAnd(productPromoConds, UtilMisc.toMap("productPromoRuleId", productPromoRule.get("productPromoRuleId")));
            // using the other method to consolidate cache entries because the same cache is used elsewhere: List productPromoConds = productPromoRule.getRelated("ProductPromoCond", null, UtilMisc.toList("productPromoCondSeqId"), true);
            if (Debug.verboseOn()) Debug.logVerbose("Checking " + productPromoConds.size() + " conditions for rule " + productPromoRule, module);

            Iterator<GenericValue> productPromoCondIter = UtilMisc.toIterator(productPromoConds);
            while (productPromoCondIter != null && productPromoCondIter.hasNext()) {
                GenericValue productPromoCond = productPromoCondIter.next();

                boolean conditionSatisfied = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);

                // any false condition will cause it to NOT perform the action
                if (!conditionSatisfied) {
                    performActions = false;
                    break;
                }
            }

            if (performActions) {
                // perform all actions, either apply or unapply

                List<GenericValue> productPromoActions = productPromoRule.getRelated("ProductPromoAction", null, UtilMisc.toList("productPromoActionSeqId"), true);
                Iterator<GenericValue> productPromoActionIter = UtilMisc.toIterator(productPromoActions);
                while (productPromoActionIter != null && productPromoActionIter.hasNext()) {
                    GenericValue productPromoAction = productPromoActionIter.next();
                    try {
                        ActionResultInfo actionResultInfo = performAction(productPromoAction, cart, delegator, dispatcher, nowTimestamp);
                        totalDiscountAmount = totalDiscountAmount.add(actionResultInfo.totalDiscountAmount);
                        quantityLeftInActions = quantityLeftInActions.add(actionResultInfo.quantityLeftInAction);

                        // only set if true, don't set back to false: implements OR logic (ie if ANY actions change content, redo loop)
                        boolean actionChangedCart = actionResultInfo.ranAction;
                        if (actionChangedCart) {
                            promoUsed = true;
                            cartChanged = true;
                        }
                    } catch (CartItemModifyException e) {
                        Debug.logError(e, "Error modifying the cart while performing promotion action [" + productPromoAction.getPrimaryKey() + "]", module);
                    }
                }
            }
        }

        if (promoUsed) {
            // Get product use information from the cart
            Map<ShoppingCartItem,BigDecimal> newUsageInfoMap = prepareProductUsageInfoMap(cart);
            Map<ShoppingCartItem,BigDecimal> deltaUsageInfoMap = prepareDeltaProductUsageInfoMap(usageInfoMap, newUsageInfoMap);
            usageInfoMap = newUsageInfoMap;
            cart.addProductPromoUse(productPromo.getString("productPromoId"), productPromoCodeId, totalDiscountAmount, quantityLeftInActions, deltaUsageInfoMap);
        } else {
            // the promotion was not used, don't try again until we finish a full pass and come back to see the promo conditions are now satisfied based on changes to the cart
            break;
        }

        if (cart.getProductPromoUseCount(productPromoId) > maxUseLimit) {
            throw new UseLimitException("ERROR: While calculating promotions the promotion [" + productPromoId + "] action was applied more than " + maxUseLimit + " times, so the calculation has been ended. This should generally never happen unless you have bad rule definitions.");
        }
    }

    return cartChanged;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:82,代码来源:ProductPromoWorker.java

示例2: performAction

import org.ofbiz.order.shoppingcart.CartItemModifyException; //导入依赖的package包/类
/** returns true if the cart was changed and rules need to be re-evaluted */
protected static ActionResultInfo performAction(GenericValue productPromoAction, ShoppingCart cart, Delegator delegator, LocalDispatcher dispatcher, Timestamp nowTimestamp) throws GenericEntityException, CartItemModifyException {
    ActionResultInfo actionResultInfo = new ActionResultInfo();
    performAction(actionResultInfo, productPromoAction, cart, delegator, dispatcher, nowTimestamp);
    return actionResultInfo;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:7,代码来源:ProductPromoWorker.java

示例3: runProductPromoRules

import org.ofbiz.order.shoppingcart.CartItemModifyException; //导入依赖的package包/类
protected static boolean runProductPromoRules(ShoppingCart cart, Long useLimit, boolean requireCode, String productPromoCodeId, Long codeUseLimit, long maxUseLimit,
    GenericValue productPromo, List<GenericValue> productPromoRules, LocalDispatcher dispatcher, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException, UseLimitException {
    boolean cartChanged = false;
    Map<ShoppingCartItem,BigDecimal> usageInfoMap = prepareProductUsageInfoMap(cart);
    String productPromoId = productPromo.getString("productPromoId");
    while ((useLimit == null || useLimit.longValue() > cart.getProductPromoUseCount(productPromoId)) &&
            (!requireCode || UtilValidate.isNotEmpty(productPromoCodeId)) &&
            (codeUseLimit == null || codeUseLimit.longValue() > cart.getProductPromoCodeUse(productPromoCodeId))) {
        boolean promoUsed = false;
        BigDecimal totalDiscountAmount = BigDecimal.ZERO;
        BigDecimal quantityLeftInActions = BigDecimal.ZERO;

        Iterator<GenericValue> promoRulesIter = productPromoRules.iterator();
        while (promoRulesIter != null && promoRulesIter.hasNext()) {
            GenericValue productPromoRule = promoRulesIter.next();

            // if apply then performActions when no conditions are false, so default to true
            boolean performActions = true;

            // loop through conditions for rule, if any false, set allConditionsTrue to false
            List<GenericValue> productPromoConds = delegator.findByAnd("ProductPromoCond", UtilMisc.toMap("productPromoId", productPromo.get("productPromoId")), UtilMisc.toList("productPromoCondSeqId"), true);
            productPromoConds = EntityUtil.filterByAnd(productPromoConds, UtilMisc.toMap("productPromoRuleId", productPromoRule.get("productPromoRuleId")));
            // using the other method to consolidate cache entries because the same cache is used elsewhere: List productPromoConds = productPromoRule.getRelated("ProductPromoCond", null, UtilMisc.toList("productPromoCondSeqId"), true);
            if (Debug.verboseOn()) Debug.logVerbose("Checking " + productPromoConds.size() + " conditions for rule " + productPromoRule, module);

            Iterator<GenericValue> productPromoCondIter = UtilMisc.toIterator(productPromoConds);
            while (productPromoCondIter != null && productPromoCondIter.hasNext()) {
                GenericValue productPromoCond = productPromoCondIter.next();

                boolean conditionSatisfied = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);

                // any false condition will cause it to NOT perform the action
                if (!conditionSatisfied) {
                    performActions = false;
                    break;
                }
            }

            if (performActions) {
                // perform all actions, either apply or unapply

                List<GenericValue> productPromoActions = productPromoRule.getRelated("ProductPromoAction", null, UtilMisc.toList("productPromoActionSeqId"), true);
                Iterator<GenericValue> productPromoActionIter = UtilMisc.toIterator(productPromoActions);
                while (productPromoActionIter != null && productPromoActionIter.hasNext()) {
                    GenericValue productPromoAction = productPromoActionIter.next();
                    try {
                        ActionResultInfo actionResultInfo = performAction(productPromoAction, cart, delegator, dispatcher, nowTimestamp);
                        totalDiscountAmount = totalDiscountAmount.add(actionResultInfo.totalDiscountAmount);
                        quantityLeftInActions = quantityLeftInActions.add(actionResultInfo.quantityLeftInAction);

                        // only set if true, don't set back to false: implements OR logic (ie if ANY actions change content, redo loop)
                        boolean actionChangedCart = actionResultInfo.ranAction;
                        if (actionChangedCart) {
                            promoUsed = true;
                            cartChanged = true;
                        }
                    } catch (CartItemModifyException e) {
                        Debug.logError(e, "Error modifying the cart while performing promotion action [" + productPromoAction.getPrimaryKey() + "]", module);
                    }
                }
            }
        }

        if (promoUsed) {
            // Get product use information from the cart
            Map<ShoppingCartItem,BigDecimal> newUsageInfoMap = prepareProductUsageInfoMap(cart);
            Map<ShoppingCartItem,BigDecimal> deltaUsageInfoMap = prepareDeltaProductUsageInfoMap(usageInfoMap, newUsageInfoMap);
            usageInfoMap = newUsageInfoMap;
            cart.addProductPromoUse(productPromo.getString("productPromoId"), productPromoCodeId, totalDiscountAmount, quantityLeftInActions, deltaUsageInfoMap);
        } else {
            // the promotion was not used, don't try again until we finish a full pass and come back to see the promo conditions are now satisfied based on changes to the cart
            break;
        }

        if (cart.getProductPromoUseCount(productPromoId) > maxUseLimit) {
            throw new UseLimitException("ERROR: While calculating promotions the promotion [" + productPromoId + "] action was applied more than " + maxUseLimit + " times, so the calculation has been ended. This should generally never happen unless you have bad rule definitions.");
        }
    }

    return cartChanged;
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:82,代码来源:ProductPromoWorker.java


注:本文中的org.ofbiz.order.shoppingcart.CartItemModifyException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。