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

📄 productstoreworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: ProductStoreWorker.java 6448 2005-12-30 09:15:30Z 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.product.store;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Random;import javax.servlet.ServletRequest;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import javolution.util.FastMap;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.common.geo.GeoWorker;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.party.contact.ContactMechWorker;import org.ofbiz.product.catalog.CatalogWorker;import org.ofbiz.product.config.ProductConfigWrapper;import org.ofbiz.product.product.ProductWorker;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ServiceUtil;/** * ProductStoreWorker - Worker class for store related functionality * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 6448 $ * @since      2.0 */public class ProductStoreWorker {    public static final String module = ProductStoreWorker.class.getName();    public static GenericValue getProductStore(String productStoreId, GenericDelegator delegator) {        if (productStoreId == null || delegator == null) {            return null;        }        GenericValue productStore = null;        try {            productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));        } catch (GenericEntityException e) {            Debug.logError(e, "Problem getting ProductStore entity", module);        }        return productStore;    }    public static GenericValue getProductStore(ServletRequest request) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        String productStoreId = ProductStoreWorker.getProductStoreId(request);        return ProductStoreWorker.getProductStore(productStoreId, delegator);    }    public static String getProductStoreId(ServletRequest request) {        HttpServletRequest httpRequest = (HttpServletRequest) request;        HttpSession session = httpRequest.getSession();        if (session.getAttribute("productStoreId") != null) {            return (String) session.getAttribute("productStoreId");        } else {            GenericValue webSite = CatalogWorker.getWebSite(request);            if (webSite != null) {                String productStoreId = webSite.getString("productStoreId");                // might be nice to do this, but not needed and has a problem with dependencies: setSessionProductStore(productStoreId, httpRequest);                return productStoreId;            }        }        return null;    }    public static String determineSingleFacilityForStore(GenericDelegator delegator, String productStoreId) {        GenericValue productStore = null;        try {            productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        if (productStore != null) {            if ("Y".equalsIgnoreCase(productStore.getString("oneInventoryFacility"))) {                return productStore.getString("inventoryFacilityId");            }        }        return null;    }    public static boolean autoSaveCart(GenericDelegator delegator, String productStoreId) {        return autoSaveCart(getProductStore(productStoreId, delegator));    }    public static boolean autoSaveCart(GenericValue productStore) {        return productStore == null ? false : "Y".equalsIgnoreCase(productStore.getString("autoSaveCart"));    }    public static String getProductStorePaymentProperties(ServletRequest request, String paymentMethodTypeId, String paymentServiceTypeEnumId, boolean anyServiceType) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        String productStoreId = ProductStoreWorker.getProductStoreId(request);        return ProductStoreWorker.getProductStorePaymentProperties(delegator, productStoreId, paymentMethodTypeId, paymentServiceTypeEnumId, anyServiceType);    }    public static String getProductStorePaymentProperties(GenericDelegator delegator, String productStoreId, String paymentMethodTypeId, String paymentServiceTypeEnumId, boolean anyServiceType) {        GenericValue setting = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStoreId, paymentMethodTypeId, paymentServiceTypeEnumId, anyServiceType);        String payProps = "payment.properties";        if (setting != null && setting.get("paymentPropertiesPath") != null) {            payProps =  setting.getString("paymentPropertiesPath");        }        return payProps;    }    public static GenericValue getProductStorePaymentSetting(GenericDelegator delegator, String productStoreId, String paymentMethodTypeId, String paymentServiceTypeEnumId, boolean anyServiceType) {        GenericValue storePayment = null;        try {            storePayment = delegator.findByPrimaryKeyCache("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId, "paymentMethodTypeId", paymentMethodTypeId, "paymentServiceTypeEnumId", paymentServiceTypeEnumId));        } catch (GenericEntityException e) {            Debug.logError(e, "Problems looking up store payment settings", module);        }        if (anyServiceType) {            if (storePayment == null) {                try {                    List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId, "paymentMethodTypeId", paymentMethodTypeId));                    storePayment = EntityUtil.getFirst(storePayments);                } catch (GenericEntityException e) {                    Debug.logError(e, "Problems looking up store payment settings", module);                }            }            if (storePayment == null) {                try {                    List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId));                    storePayment = EntityUtil.getFirst(storePayments);                } catch (GenericEntityException e) {                    Debug.logError(e, "Problems looking up store payment settings", module);                }            }        }        return storePayment;    }    public static GenericValue getProductStoreShipmentMethod(GenericDelegator delegator, String productStoreId,                                                             String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId) {        // check for an external service call        Map storeFields = UtilMisc.toMap("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId,                "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId);        GenericValue storeShipMeth = null;        try {            storeShipMeth = delegator.findByPrimaryKeyCache("ProductStoreShipmentMeth", storeFields);        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        return storeShipMeth;    }    public static List getAvailableStoreShippingMethods(GenericDelegator delegator, String productStoreId, GenericValue shippingAddress, List itemSizes, Map featureIdMap, double weight, double orderTotal) {        if (featureIdMap == null) {            featureIdMap = new HashMap();        }        List shippingMethods = null;        try {            shippingMethods = delegator.findByAndCache("ProductStoreShipmentMethView", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNumber"));        } catch (GenericEntityException e) {            Debug.logError(e, "Unable to get ProductStore shipping methods", module);            return null;        }        // clone the list for concurrent modification        List returnShippingMethods = new LinkedList(shippingMethods);        if (shippingMethods != null) {            Iterator i = shippingMethods.iterator();            while (i.hasNext()) {                GenericValue method = (GenericValue) i.next();                //Debug.logInfo("Checking Shipping Method : " + method.getString("shipmentMethodTypeId"), module);                // test min/max weight first                Double minWeight = method.getDouble("minWeight");                Double maxWeight = method.getDouble("maxWeight");                if (minWeight != null && minWeight.doubleValue() > 0 && minWeight.doubleValue() > weight) {                    returnShippingMethods.remove(method);                    //Debug.logInfo("Removed shipping method due to not enough weight", module);                    continue;                }                if (maxWeight != null && maxWeight.doubleValue() > 0 && maxWeight.doubleValue() < weight) {                    returnShippingMethods.remove(method);                    //Debug.logInfo("Removed shipping method due to too much weight", module);                    continue;                }                // test order total                Double minTotal = method.getDouble("minTotal");                Double maxTotal = method.getDouble("maxTotal");                if (minTotal != null && minTotal.doubleValue() > 0 && minTotal.doubleValue() > orderTotal) {                    returnShippingMethods.remove(method);                    //Debug.logInfo("Removed shipping method due to not enough order total", module);                    continue;                }                if (maxTotal != null && maxTotal.doubleValue() > 0 && maxTotal.doubleValue() < orderTotal) {                    returnShippingMethods.remove(method);                    //Debug.logInfo("Removed shipping method due to too much shipping total", module);                    continue;                }                // test product sizes                Double minSize = method.getDouble("minSize");

⌨️ 快捷键说明

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