📄 productstoreworker.java
字号:
surveys.add(surveyAppl); } else if ((virtualProductId != null) && (surveyAppl.getString("productId").equals(virtualProductId))) { 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 != 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; } /** 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(ServletRequest request, GenericValue product) { return isStoreInventoryRequiredAndAvailable(request, product, null, Boolean.TRUE, null); } public static boolean isStoreInventoryAvailable(ServletRequest request, GenericValue product, Double quantity) { return isStoreInventoryRequiredAndAvailable(request, product, quantity, null, Boolean.TRUE); } /** * This method is used in the showcart pages to determine whether or not to show the inventory message and * in the productdetail pages to determine whether or not to show the item as out of stock. * * @param request ServletRequest (or HttpServletRequest of course) * @param product GenericValue representing the product in question * @param quantity Quantity desired. * @param wantRequired If true then inventory required must be true for the result to be true, if false must be false; if null don't care * @param wantAvailable If true then inventory avilable must be true for the result to be true, if false must be false; if null don't care */ public static boolean isStoreInventoryRequiredAndAvailable(ServletRequest request, GenericValue product, Double quantity, Boolean wantRequired, Boolean wantAvailable) { GenericValue productStore = getProductStore(request); if (productStore == null) { Debug.logWarning("No ProductStore found, return false for inventory check", module); return false; } if (product == null) { Debug.logWarning("No Product passed, return false for inventory check", module); return false; } if (quantity == null) quantity = new Double(1); String productStoreId = productStore.getString("productStoreId"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); try { Boolean requiredOkay = null; if (wantRequired != null) { Map invReqResult = dispatcher.runSync("isStoreInventoryRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "productStore", productStore)); if (ServiceUtil.isError(invReqResult)) { Debug.logError("Error calling isStoreInventoryRequired service, result is: " + invReqResult, module); return false; } requiredOkay = new Boolean(wantRequired.booleanValue() == "Y".equals((String) invReqResult.get("requireInventory"))); } Boolean availableOkay = null; if (wantAvailable != null) { Map invAvailResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "productStore", productStore, "quantity", quantity)); if (ServiceUtil.isError(invAvailResult)) { Debug.logError("Error calling isStoreInventoryAvailable service, result is: " + invAvailResult, module); return false; } availableOkay = new Boolean(wantAvailable.booleanValue() == "Y".equals((String) invAvailResult.get("available"))); } if ((requiredOkay == null || requiredOkay.booleanValue()) && (availableOkay == null || availableOkay.booleanValue())) { return true; } else { return false; } } catch (GenericServiceException e) { String errMsg = "Fatal error calling inventory checking services: " + e.toString(); Debug.logError(e, errMsg, module); return false; } } public static boolean isStoreInventoryAvailable(ServletRequest request, ProductConfigWrapper productConfig, double quantity) { GenericValue productStore = getProductStore(request); if (productStore == null) { Debug.logWarning("No ProductStore found, return false for inventory check", module); return false; } String productStoreId = productStore.getString("productStoreId"); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); return isStoreInventoryAvailable(productStoreId, productConfig, quantity, delegator, dispatcher); } /** check inventory availability for the given catalog, product, quantity, etc */ public static boolean isStoreInventoryAvailable(String productStoreId, ProductConfigWrapper productConfig, double quantity, GenericDelegator delegator, LocalDispatcher dispatcher) { GenericValue productStore = getProductStore(productStoreId, delegator); if (productStore == null) { Debug.logWarning("No ProductStore found with id " + productStoreId + ", returning false for inventory available check", module); return false; } // if prodCatalog is set to not check inventory break here if ("N".equals(productStore.getString("checkInventory"))) { // note: if not set, defaults to yes, check inventory if (Debug.verboseOn()) Debug.logVerbose("ProductStore with id " + productStoreId + ", is set to NOT check inventory, returning true for inventory available check", module); return true; } boolean isInventoryAvailable = false; if ("Y".equals(productStore.getString("oneInventoryFacility"))) { String inventoryFacilityId = productStore.getString("inventoryFacilityId"); if (UtilValidate.isEmpty(inventoryFacilityId)) { Debug.logWarning("ProductStore with id " + productStoreId + " has Y for oneInventoryFacility but inventoryFacilityId is empty, returning false for inventory check", module); return false; } try { isInventoryAvailable = ProductWorker.isProductInventoryAvailableByFacility(productConfig, inventoryFacilityId, quantity, dispatcher); } catch (GenericServiceException e) { Debug.logWarning(e, "Error invoking isProductInventoryAvailableByFacility in isCatalogInventoryAvailable", module); return false; } return isInventoryAvailable; } else { GenericValue product = productConfig.getProduct();; List productFacilities = null; try { productFacilities = delegator.getRelatedCache("ProductFacility", product); } catch (GenericEntityException e) { Debug.logWarning(e, "Error invoking getRelatedCache in isCatalogInventoryAvailable", module); return false; } if (productFacilities != null && productFacilities.size() > 0) { Iterator pfIter = productFacilities.iterator(); while (pfIter.hasNext()) { try { GenericValue pfValue = (GenericValue) pfIter.next(); isInventoryAvailable = ProductWorker.isProductInventoryAvailableByFacility(productConfig, pfValue.getString("facilityId"), quantity, dispatcher); if (isInventoryAvailable == true) { return isInventoryAvailable; } } catch (GenericServiceException e) { Debug.logWarning(e, "Error invoking isProductInventoryAvailableByFacility in isCatalogInventoryAvailable", module); return false; } } } return false; } } protected static Map defaultProductStoreEmailScreenLocation = FastMap.newInstance(); static { defaultProductStoreEmailScreenLocation.put("PRDS_ODR_CONFIRM", "component://ecommerce/widget/EmailOrderScreens.xml#OrderConfirmNotice"); defaultProductStoreEmailScreenLocation.put("PRDS_ODR_COMPLETE", "component://ecommerce/widget/EmailOrderScreens.xml#OrderCompleteNotice"); defaultProductStoreEmailScreenLocation.put("PRDS_ODR_BACKORDER", "component://ecommerce/widget/EmailOrderScreens.xml#BackorderNotice"); defaultProductStoreEmailScreenLocation.put("PRDS_ODR_CHANGE", "component://ecommerce/widget/EmailOrderScreens.xml#OrderChangeNotice"); defaultProductStoreEmailScreenLocation.put("PRDS_ODR_PAYRETRY", "component://ecommerce/widget/EmailOrderScreens.xml#PaymentRetryNotice"); defaultProductStoreEmailScreenLocation.put("PRDS_RTN_ACCEPT", "component://ecommerce/widget/EmailReturnScreens.xml#ReturnAccept"); defaultProductStoreEmailScreenLocation.put("PRDS_RTN_COMPLETE", "component://ecommerce/widget/EmailReturnScreens.xml#ReturnComplete"); defaultProductStoreEmailScreenLocation.put("PRDS_RTN_CANCEL", "component://ecommerce/widget/EmailReturnScreens.xml#ReturnCancel"); defaultProductStoreEmailScreenLocation.put("PRDS_GC_PURCHASE", "component://ecommerce/widget/EmailGiftCardScreens.xml#GiftCardPurchase"); defaultProductStoreEmailScreenLocation.put("PRDS_GC_RELOAD", "component://ecommerce/widget/EmailGiftCardScreens.xml#GiftCardReload"); } public static String getDefaultProductStoreEmailScreenLocation(String emailType) { return (String) defaultProductStoreEmailScreenLocation.get(emailType); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -