當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。