📄 productstoreworker.java
字号:
/*
* $Id: ProductStoreWorker.java,v 1.23 2004/02/28 23:35:23 ajzeneski Exp $
*
* Copyright (c) 2001, 2002 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.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.ofbiz.base.util.Debug;
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.product.ProductWorker;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
/**
* ProductStoreWorker - Worker class for store related functionality
*
* @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
* @version $Revision: 1.23 $
* @since 2.0
*/
public class ProductStoreWorker {
public static final String module = ProductStoreWorker.class.getName();
public static GenericValue getProductStore(String productStoreId, GenericDelegator delegator) {
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) {
return webSite.getString("productStoreId");
}
}
return null;
}
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 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");
Double maxSize = method.getDouble("maxSize");
if (minSize != null && minSize.doubleValue() > 0) {
boolean allMatch = false;
if (itemSizes != null) {
allMatch = true;
Iterator isi = itemSizes.iterator();
while (isi.hasNext()) {
Double size = (Double) isi.next();
if (size.doubleValue() < minSize.doubleValue()) {
allMatch = false;
}
}
}
if (!allMatch) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method because not all products are less then min size", module);
continue;
}
}
if (maxSize != null && maxSize.doubleValue() > 0) {
boolean allMatch = false;
if (itemSizes != null) {
allMatch = true;
Iterator isi = itemSizes.iterator();
while (isi.hasNext()) {
Double size = (Double) isi.next();
if (size.doubleValue() > maxSize.doubleValue()) {
allMatch = false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -