⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productpromoworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: ProductPromoWorker.java 7355 2006-04-20 21:32:54Z jonesde $ * *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.order.shoppingcart.product;import java.sql.Timestamp;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;import javax.servlet.ServletRequest;import javax.servlet.http.HttpServletRequest;import javolution.util.FastList;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.order.shoppingcart.CartItemModifyException;import org.ofbiz.order.shoppingcart.ShoppingCart;import org.ofbiz.order.shoppingcart.ShoppingCartEvents;import org.ofbiz.order.shoppingcart.ShoppingCartItem;import org.ofbiz.product.product.ProductContentWrapper;import org.ofbiz.product.product.ProductSearch;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;/** * ProductPromoWorker - Worker class for catalog/product promotion related functionality * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 7355 $ * @since      2.0 */public class ProductPromoWorker {    public static final String module = ProductPromoWorker.class.getName();    public static final String resource_error = "OrderErrorUiLabels";    public static List getStoreProductPromos(GenericDelegator delegator, LocalDispatcher dispatcher, ServletRequest request) {        List productPromos = FastList.newInstance();        Timestamp nowTimestamp = UtilDateTime.nowTimestamp();        // get the ShoppingCart out of the session.        HttpServletRequest req = null;        ShoppingCart cart = null;        try {            req = (HttpServletRequest) request;            cart = ShoppingCartEvents.getCartObject(req);        } catch (ClassCastException cce) {            Debug.logError("Not a HttpServletRequest, no shopping cart found.", module);            return null;        } catch (IllegalArgumentException e) {            Debug.logError(e, module);            return null;        }        boolean condResult = true;        try {            String productStoreId = cart.getProductStoreId();            GenericValue productStore = null;            try {                productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));            } catch (GenericEntityException e) {                Debug.logError(e, "Error looking up store with id " + productStoreId, module);            }            if (productStore == null) {                Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderNoStoreFoundWithIdNotDoingPromotions", UtilMisc.toMap("productStoreId",productStoreId), cart.getLocale()), module);                return productPromos;            }            if (productStore != null) {                Iterator productStorePromoAppls = UtilMisc.toIterator(EntityUtil.filterByDate(productStore.getRelatedCache("ProductStorePromoAppl", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum")), true));                while (productStorePromoAppls != null && productStorePromoAppls.hasNext()) {                    GenericValue productStorePromoAppl = (GenericValue) productStorePromoAppls.next();                    GenericValue productPromo = productStorePromoAppl.getRelatedOneCache("ProductPromo");                    List productPromoRules = productPromo.getRelatedCache("ProductPromoRule", null, null);                    if (productPromoRules != null) {                        Iterator promoRulesItr = productPromoRules.iterator();                        while (condResult && promoRulesItr != null && promoRulesItr.hasNext()) {                            GenericValue promoRule = (GenericValue) promoRulesItr.next();                            Iterator productPromoConds = UtilMisc.toIterator(promoRule.getRelatedCache("ProductPromoCond", null, UtilMisc.toList("productPromoCondSeqId")));                            while (condResult && productPromoConds != null && productPromoConds.hasNext()) {                                GenericValue productPromoCond = (GenericValue) productPromoConds.next();                                // evaluate the party related conditions; so we don't show the promo if it doesn't apply.                                if ("PPIP_PARTY_ID".equals(productPromoCond.getString("inputParamEnumId"))) {                                    condResult = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);                                } else if ("PPIP_PARTY_GRP_MEM".equals(productPromoCond.getString("inputParamEnumId"))) {                                    condResult = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);                                } else if ("PPIP_PARTY_CLASS".equals(productPromoCond.getString("inputParamEnumId"))) {                                    condResult = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);                                } else if ("PPIP_ROLE_TYPE".equals(productPromoCond.getString("inputParamEnumId"))) {                                    condResult = checkCondition(productPromoCond, cart, delegator, dispatcher, nowTimestamp);                                }                            }                        }                        if (!condResult) productPromo = null;                    }                    if (productPromo != null) productPromos.add(productPromo);                }            }        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        return productPromos;    }    public static List getProductStorePromotions(ShoppingCart cart, Timestamp nowTimestamp, LocalDispatcher dispatcher) {        List productPromoList = FastList.newInstance();                GenericDelegator delegator = cart.getDelegator();        String productStoreId = cart.getProductStoreId();        GenericValue productStore = null;        try {            productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));        } catch (GenericEntityException e) {            Debug.logError(e, "Error looking up store with id " + productStoreId, module);        }        if (productStore == null) {            Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderNoStoreFoundWithIdNotDoingPromotions", UtilMisc.toMap("productStoreId",productStoreId), cart.getLocale()), module);            return productPromoList;        }        try {            // loop through promotions and get a list of all of the rules...            List productStorePromoApplsList = productStore.getRelatedCache("ProductStorePromoAppl", null, UtilMisc.toList("sequenceNum"));            productStorePromoApplsList = EntityUtil.filterByDate(productStorePromoApplsList, nowTimestamp);            if (productStorePromoApplsList == null || productStorePromoApplsList.size() == 0) {                if (Debug.verboseOn()) Debug.logVerbose("Not doing promotions, none applied to store with ID " + productStoreId, module);            }            Iterator prodCatalogPromoAppls = UtilMisc.toIterator(productStorePromoApplsList);            while (prodCatalogPromoAppls != null && prodCatalogPromoAppls.hasNext()) {                GenericValue prodCatalogPromoAppl = (GenericValue) prodCatalogPromoAppls.next();                GenericValue productPromo = prodCatalogPromoAppl.getRelatedOneCache("ProductPromo");                productPromoList.add(productPromo);            }        } catch (GenericEntityException e) {            Debug.logError(e, "Error looking up promotion data while doing promotions", module);        }        return productPromoList;    }    public static List getAgreementPromotions(ShoppingCart cart, Timestamp nowTimestamp, LocalDispatcher dispatcher) {        List productPromoList = FastList.newInstance();                GenericDelegator delegator = cart.getDelegator();        String agreementId = cart.getAgreementId();        GenericValue agreement = null;        try {            agreement = delegator.findByPrimaryKeyCache("Agreement", UtilMisc.toMap("agreementId", agreementId));        } catch (GenericEntityException e) {            Debug.logError(e, "Error looking up agreement with id " + agreementId, module);        }        if (agreement == null) {            Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderNoAgreementFoundWithIdNotDoingPromotions", UtilMisc.toMap("agreementId", agreementId), cart.getLocale()), module);            return productPromoList;        }        GenericValue agreementItem = null;        try {            List agreementItems = delegator.findByAndCache("AgreementItem", UtilMisc.toMap("agreementId", agreementId, "agreementItemTypeId", "AGREEMENT_PRICING_PR", "currencyUomId", cart.getCurrency()));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -