📄 productstoreworker.java
字号:
}
if (!allMatch) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method because one or more products were more then max size", module);
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);
Debug.logInfo("Remove shipping method due to USPS address", module);
continue;
}
if ("Y".equals(requireUspsAddr) && !isUspsAddress) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method due to NON-USPS address", module);
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);
Debug.logInfo("Removed shipping method due to Company address", module);
continue;
}
if ("Y".equals(requireCompanyAddr) && !isCompanyAddress) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method due to NON-Company address", module);
continue;
}
// check the items excluded from shipping
String includeFreeShipping = method.getString("includeNoChargeItems");
if (includeFreeShipping != null && "N".equalsIgnoreCase(includeFreeShipping)) {
if ((itemSizes == null || itemSizes.size() == 0) && orderTotal == 0) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method due to all items being exempt from shipping", module);
continue;
}
}
// check the geos
String includeGeoId = method.getString("includeGeoId");
String excludeGeoId = method.getString("excludeGeoId");
if ((includeGeoId != null && includeGeoId.length() > 0) || (excludeGeoId != null && excludeGeoId.length() > 0)) {
if (shippingAddress == null) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method due to empty shipping adresss (may not have been selected yet)", module);
continue;
}
}
if (includeGeoId != null && includeGeoId.length() > 0) {
List 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);
Debug.logInfo("Removed shipping method due to being outside the included GEO", module);
continue;
}
}
if (excludeGeoId != null && excludeGeoId.length() > 0) {
List 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);
Debug.logInfo("Removed shipping method due to being inside the excluded GEO", module);
continue;
}
}
// check the features
String includeFeatures = method.getString("includeFeatureGroup");
String excludeFeatures = method.getString("excludeFeatureGroup");
if (includeFeatures != null && includeFeatures.length() > 0) {
List includedFeatures = null;
try {
includedFeatures = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", includeFeatures));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + includeFeatures, module);
}
if (includedFeatures != null) {
boolean foundOne = false;
Iterator ifet = includedFeatures.iterator();
while (ifet.hasNext()) {
GenericValue appl = (GenericValue) ifet.next();
if (featureIdMap.containsKey(appl.getString("productFeatureId"))) {
foundOne = true;
break;
}
}
if (!foundOne) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method due to no required features found", module);
continue;
}
}
}
if (excludeFeatures != null && excludeFeatures.length() > 0) {
List excludedFeatures = null;
try {
excludedFeatures = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", excludeFeatures));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + excludeFeatures, module);
}
if (excludedFeatures != null) {
Iterator ifet = excludedFeatures.iterator();
while (ifet.hasNext()) {
GenericValue appl = (GenericValue) ifet.next();
if (featureIdMap.containsKey(appl.getString("productFeatureId"))) {
returnShippingMethods.remove(method);
Debug.logInfo("Removed shipping method due to an exluded feature being found : " + appl.getString("productFeatureId"), module);
continue;
}
}
}
}
}
}
return returnShippingMethods;
}
public static List getProductSurveys(GenericDelegator delegator, String productStoreId, String productId, String surveyApplTypeId) {
List surveys = new ArrayList();
List storeSurveys = null;
try {
storeSurveys = delegator.findByAndCache("ProductStoreSurveyAppl", UtilMisc.toMap("productStoreId", productStoreId, "surveyApplTypeId", surveyApplTypeId), UtilMisc.toList("sequenceNum"));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductStoreSurveyAppl for store : " + productStoreId, module);
}
storeSurveys = EntityUtil.filterByDate(storeSurveys);
// null productId means get all of this trigger (appl) type
if (productId == null) {
return storeSurveys;
}
if (storeSurveys != null && storeSurveys.size() > 0) {
Iterator ssi = storeSurveys.iterator();
while (ssi.hasNext()) {
GenericValue surveyAppl = (GenericValue) ssi.next();
if (surveyAppl.get("productId") != null && productId.equals(surveyAppl.get("productId"))) {
surveys.add(surveyAppl);
} else if (surveyAppl.get("productCategoryId") != null) {
List categoryMembers = null;
try {
categoryMembers = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", surveyAppl.get("productCategoryId")));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductCategoryMemebr records for survey application : " + surveyAppl, module);
}
if (categoryMembers != null) {
Iterator cmi = categoryMembers.iterator();
while (cmi.hasNext()) {
GenericValue member = (GenericValue) cmi.next();
if (productId.equals(member.getString("productId"))) {
surveys.add(surveyAppl);
break;
}
}
}
}
}
}
return surveys;
}
/** Returns the number of responses for this survey by party */
public static int checkSurveyResponse(HttpServletRequest request, String surveyId) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
String productStoreId = getProductStoreId(request);
if (userLogin == null) {
return -1;
}
return checkSurveyResponse(delegator, userLogin.getString("partyId"), productStoreId, surveyId);
}
/** Returns the number of responses for this survey by party */
public static int checkSurveyResponse(GenericDelegator delegator, String partyId, String productStoreId, String surveyId) {
if (delegator == null || partyId == null || productStoreId == null) {
return -1;
}
List surveyResponse = null;
try {
surveyResponse = delegator.findByAnd("SurveyResponse", UtilMisc.toMap("surveyId", surveyId, "partyId", partyId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
return -1;
}
if (surveyResponse == null || surveyResponse.size() == 0) {
return 0;
} else {
return surveyResponse.size();
}
}
public static boolean isStoreInventoryRequired(String productStoreId, String productId, GenericDelegator delegator) {
GenericValue product = null;
if (productId != null) {
try {
product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
} catch (GenericEntityException e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -