use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.
the class ProductStoreWorker method getAvailableStoreShippingMethods.
public static List<GenericValue> getAvailableStoreShippingMethods(Delegator delegator, String productStoreId, GenericValue shippingAddress, List<BigDecimal> itemSizes, Map<String, BigDecimal> featureIdMap, BigDecimal weight, BigDecimal orderTotal) {
if (featureIdMap == null) {
featureIdMap = new HashMap<String, BigDecimal>();
}
List<GenericValue> shippingMethods = null;
try {
shippingMethods = EntityQuery.use(delegator).from("ProductStoreShipmentMethView").where("productStoreId", productStoreId).orderBy("sequenceNumber").cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductStore shipping methods", module);
return null;
}
// clone the list for concurrent modification
List<GenericValue> returnShippingMethods = UtilMisc.makeListWritable(shippingMethods);
if (shippingMethods != null) {
for (GenericValue method : shippingMethods) {
// test min/max weight first
BigDecimal minWeight = method.getBigDecimal("minWeight");
BigDecimal maxWeight = method.getBigDecimal("maxWeight");
if (minWeight != null && minWeight.compareTo(BigDecimal.ZERO) > 0 && minWeight.compareTo(weight) > 0) {
returnShippingMethods.remove(method);
continue;
}
if (maxWeight != null && maxWeight.compareTo(BigDecimal.ZERO) > 0 && maxWeight.compareTo(weight) < 0) {
returnShippingMethods.remove(method);
continue;
}
// test order total
BigDecimal minTotal = method.getBigDecimal("minTotal");
BigDecimal maxTotal = method.getBigDecimal("maxTotal");
if (minTotal != null && minTotal.compareTo(BigDecimal.ZERO) > 0 && minTotal.compareTo(orderTotal) > 0) {
returnShippingMethods.remove(method);
continue;
}
if (maxTotal != null && maxTotal.compareTo(BigDecimal.ZERO) > 0 && maxTotal.compareTo(orderTotal) < 0) {
returnShippingMethods.remove(method);
continue;
}
// test product sizes
BigDecimal minSize = method.getBigDecimal("minSize");
BigDecimal maxSize = method.getBigDecimal("maxSize");
if (minSize != null && minSize.compareTo(BigDecimal.ZERO) > 0) {
boolean allMatch = false;
if (itemSizes != null) {
allMatch = true;
for (BigDecimal size : itemSizes) {
if (size.compareTo(minSize) < 0) {
allMatch = false;
}
}
}
if (!allMatch) {
returnShippingMethods.remove(method);
continue;
}
}
if (maxSize != null && maxSize.compareTo(BigDecimal.ZERO) > 0) {
boolean allMatch = false;
if (itemSizes != null) {
allMatch = true;
for (BigDecimal size : itemSizes) {
if (size.compareTo(maxSize) > 0) {
allMatch = false;
}
}
}
if (!allMatch) {
returnShippingMethods.remove(method);
continue;
}
}
// check USPS address
String allowUspsAddr = method.getString("allowUspsAddr");
String requireUspsAddr = method.getString("requireUspsAddr");
boolean isUspsAddress = ContactMechWorker.isUspsAddress(shippingAddress);
if ("N".equals(allowUspsAddr) && isUspsAddress) {
returnShippingMethods.remove(method);
continue;
}
if ("Y".equals(requireUspsAddr) && !isUspsAddress) {
returnShippingMethods.remove(method);
continue;
}
// check company address
String companyPartyId = method.getString("companyPartyId");
String allowCompanyAddr = method.getString("allowCompanyAddr");
String requireCompanyAddr = method.getString("requireCompanyAddr");
boolean isCompanyAddress = ContactMechWorker.isCompanyAddress(shippingAddress, companyPartyId);
if ("N".equals(allowCompanyAddr) && isCompanyAddress) {
returnShippingMethods.remove(method);
continue;
}
if ("Y".equals(requireCompanyAddr) && !isCompanyAddress) {
returnShippingMethods.remove(method);
continue;
}
// check the items excluded from shipping
String includeFreeShipping = method.getString("includeNoChargeItems");
if (includeFreeShipping != null && "N".equalsIgnoreCase(includeFreeShipping)) {
if (UtilValidate.isEmpty(itemSizes) && orderTotal.compareTo(BigDecimal.ZERO) == 0) {
returnShippingMethods.remove(method);
continue;
}
}
// check the geos
String includeGeoId = method.getString("includeGeoId");
String excludeGeoId = method.getString("excludeGeoId");
if (UtilValidate.isNotEmpty(includeGeoId) || UtilValidate.isNotEmpty(excludeGeoId)) {
if (shippingAddress == null) {
returnShippingMethods.remove(method);
continue;
}
}
if (UtilValidate.isNotEmpty(includeGeoId)) {
List<GenericValue> includeGeoGroup = GeoWorker.expandGeoGroup(includeGeoId, delegator);
if (!GeoWorker.containsGeo(includeGeoGroup, shippingAddress.getString("countryGeoId"), delegator) && !GeoWorker.containsGeo(includeGeoGroup, shippingAddress.getString("stateProvinceGeoId"), delegator) && !GeoWorker.containsGeo(includeGeoGroup, shippingAddress.getString("postalCodeGeoId"), delegator)) {
// not in required included geos
returnShippingMethods.remove(method);
continue;
}
}
if (UtilValidate.isNotEmpty(excludeGeoId)) {
List<GenericValue> excludeGeoGroup = GeoWorker.expandGeoGroup(excludeGeoId, delegator);
if (GeoWorker.containsGeo(excludeGeoGroup, shippingAddress.getString("countryGeoId"), delegator) || GeoWorker.containsGeo(excludeGeoGroup, shippingAddress.getString("stateProvinceGeoId"), delegator) || GeoWorker.containsGeo(excludeGeoGroup, shippingAddress.getString("postalCodeGeoId"), delegator)) {
// in excluded geos
returnShippingMethods.remove(method);
continue;
}
}
// check the features
String includeFeatures = method.getString("includeFeatureGroup");
String excludeFeatures = method.getString("excludeFeatureGroup");
if (UtilValidate.isNotEmpty(includeFeatures)) {
List<GenericValue> includedFeatures = null;
try {
includedFeatures = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureGroupId", includeFeatures).cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + includeFeatures, module);
}
if (includedFeatures != null) {
boolean foundOne = false;
for (GenericValue appl : includedFeatures) {
if (featureIdMap.containsKey(appl.getString("productFeatureId"))) {
foundOne = true;
break;
}
}
if (!foundOne) {
returnShippingMethods.remove(method);
continue;
}
}
}
if (UtilValidate.isNotEmpty(excludeFeatures)) {
List<GenericValue> excludedFeatures = null;
try {
excludedFeatures = EntityQuery.use(delegator).from("ProductFeatureGroupAppl").where("productFeatureGroupId", excludeFeatures).cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + excludeFeatures, module);
}
if (excludedFeatures != null) {
for (GenericValue appl : excludedFeatures) {
if (featureIdMap.containsKey(appl.getString("productFeatureId"))) {
returnShippingMethods.remove(method);
continue;
}
}
}
}
}
}
return returnShippingMethods;
}
use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.
the class ProductStoreWorker method getRandomSurveyWrapper.
public static ProductStoreSurveyWrapper getRandomSurveyWrapper(HttpServletRequest request, String groupName) {
GenericValue productStore = getProductStore(request);
HttpSession session = request.getSession();
if (productStore == null) {
return null;
}
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
if (userLogin == null) {
userLogin = (GenericValue) session.getAttribute("autoUserLogin");
}
String partyId = userLogin != null ? userLogin.getString("partyId") : null;
String origParamMapId = UtilHttp.stashParameterMap(request);
Map<String, Object> passThruFields = UtilMisc.<String, Object>toMap("_ORIG_PARAM_MAP_ID_", origParamMapId);
return getRandomSurveyWrapper(productStore.getDelegator(), productStore.getString("productStoreId"), groupName, partyId, passThruFields);
}
use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.
the class ProductStoreWorker method getSurveys.
public static List<GenericValue> getSurveys(Delegator delegator, String productStoreId, String groupName, String productId, String surveyApplTypeId, String parentProductId) {
List<GenericValue> surveys = new LinkedList<GenericValue>();
List<GenericValue> storeSurveys = null;
try {
storeSurveys = EntityQuery.use(delegator).from("ProductStoreSurveyAppl").where("productStoreId", productStoreId, "surveyApplTypeId", surveyApplTypeId).orderBy("sequenceNum").cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductStoreSurveyAppl for store : " + productStoreId, module);
return surveys;
}
// limit by date
storeSurveys = EntityUtil.filterByDate(storeSurveys);
// limit based on group name
if (UtilValidate.isNotEmpty(groupName)) {
storeSurveys = EntityUtil.filterByAnd(storeSurveys, UtilMisc.toMap("groupName", groupName));
}
Debug.logInfo("getSurvey for product " + productId, module);
// limit by product
if (UtilValidate.isNotEmpty(productId) && UtilValidate.isNotEmpty(storeSurveys)) {
for (GenericValue surveyAppl : storeSurveys) {
GenericValue product = null;
String virtualProductId = null;
// if the item is a variant, get its virtual productId
try {
product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache().queryOne();
if ((product != null) && ("Y".equals(product.get("isVariant")))) {
if (parentProductId != null) {
virtualProductId = parentProductId;
} else {
virtualProductId = ProductWorker.getVariantVirtualId(product);
}
Debug.logInfo("getSurvey for virtual product " + virtualProductId, module);
}
} catch (GenericEntityException e) {
Debug.logError(e, "Problem finding product from productId " + productId, module);
}
// use survey if productId or virtualProductId of the variant product is in the ProductStoreSurveyAppl
if (surveyAppl.get("productId") != null) {
if (surveyAppl.get("productId").equals(productId)) {
surveys.add(surveyAppl);
} else if ((virtualProductId != null) && (surveyAppl.getString("productId").equals(virtualProductId))) {
surveys.add(surveyAppl);
}
} else if (surveyAppl.get("productCategoryId") != null) {
List<GenericValue> categoryMembers = null;
try {
categoryMembers = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", surveyAppl.get("productCategoryId")).cache(true).queryList();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductCategoryMember records for survey application : " + surveyAppl, module);
}
if (categoryMembers != null) {
for (GenericValue member : categoryMembers) {
if (productId != null && productId.equals(member.getString("productId"))) {
surveys.add(surveyAppl);
break;
} else if ((virtualProductId != null) && (virtualProductId.equals(member.getString("productId")))) {
// similarly, check if virtual productId is in category
surveys.add(surveyAppl);
break;
}
}
}
}
}
} else if (storeSurveys != null) {
surveys.addAll(storeSurveys);
}
return surveys;
}
use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.
the class ProductStoreWorker method getProductStoreId.
public static String getProductStoreId(ServletRequest request) {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpSession session = httpRequest.getSession(false);
if (session != null && session.getAttribute("productStoreId") != null) {
return (String) session.getAttribute("productStoreId");
} else {
GenericValue webSite = WebSiteWorker.getWebSite(httpRequest);
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;
}
use of org.apache.ofbiz.entity.GenericValue in project ofbiz-framework by apache.
the class SupplierProductServices method convertFeaturesForSupplier.
/*
* Parameters: partyId of a supplier and productFeatures, a Collection (usually List) of product features
* Service will convert each feature in the Collection, changing their idCode and description based on the
* SupplierProduct entity for that supplier party and feature, and return it as convertedProductFeatures
*/
public static Map<String, Object> convertFeaturesForSupplier(DispatchContext dctx, Map<String, ? extends Object> context) {
Map<String, Object> results;
String partyId = (String) context.get("partyId");
Collection<GenericValue> features = UtilGenerics.checkList(context.get("productFeatures"));
try {
if (partyId != null && UtilValidate.isNotEmpty(features)) {
// substitue description and idCode
for (GenericValue nextFeature : features) {
List<GenericValue> supplierFeatures = EntityUtil.filterByAnd(nextFeature.getRelated("SupplierProductFeature", null, null, false), UtilMisc.toMap("partyId", partyId));
GenericValue supplierFeature = null;
if ((supplierFeatures != null) && (supplierFeatures.size() > 0)) {
supplierFeature = supplierFeatures.get(0);
if (supplierFeature.get("description") != null) {
nextFeature.put("description", supplierFeature.get("description"));
}
if (supplierFeature.get("idCode") != null) {
nextFeature.put("idCode", supplierFeature.get("idCode"));
}
// TODO: later, do some kind of uom/quantity conoversion with the UomConversion entity
}
}
}
results = ServiceUtil.returnSuccess();
results.put("convertedProductFeatures", features);
} catch (GenericEntityException ex) {
Debug.logError(ex, ex.getMessage(), module);
return ServiceUtil.returnError(ex.getMessage());
}
return results;
}
Aggregations