📄 productservices.java
字号:
// check to see if salesDiscontinuationDate has passed if (productTo.get("salesDiscontinuationDate") != null && nowTimestamp.after(productTo.getTimestamp("salesDiscontinuationDate"))) { if (Debug.verboseOn()) { String excMsg = "Tried to view the Product " + productTo.getString("productName") + " (productId: " + productTo.getString("productId") + ") as a variant. This product is no longer available for sale, so not adding for view."; Debug.logVerbose(excMsg, module); } continue; } // next check inventory for each item: if inventory is not required or is available try { Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", new Double(1.0))); if (ServiceUtil.isError(invReqResult)) { return ServiceUtil.returnError("Error calling the isStoreInventoryRequired when building the variant product tree.", null, null, invReqResult); } else if ("Y".equals((String) invReqResult.get("availableOrNotRequired"))) { items.add(productIdTo); if (productTo.getString("isVirtual") != null && productTo.getString("isVirtual").equals("Y")) { virtualVariant.add(productIdTo); } } } catch (GenericServiceException e) { String errMsg = "Error calling the isStoreInventoryRequired when building the variant product tree: " + e.toString(); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } } String productId = (String) context.get("productId"); // Make the selectable feature list List selectableFeatures = null; try { Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"); List sort = UtilMisc.toList("sequenceNum"); selectableFeatures = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort); selectableFeatures = EntityUtil.filterByDate(selectableFeatures, true); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource,"productservices.empty_list_of_selectable_features_found", locale)); } Map features = new HashMap(); Iterator sFIt = selectableFeatures.iterator(); while (sFIt.hasNext()) { GenericValue v = (GenericValue) sFIt.next(); String featureType = v.getString("productFeatureTypeId"); String feature = v.getString("description"); if (!features.containsKey(featureType)) { List featureList = new LinkedList(); featureList.add(feature); features.put(featureType, featureList); } else { List featureList = (LinkedList) features.get(featureType); featureList.add(feature); features.put(featureType, featureList); } } Map tree = null; try { tree = makeGroup(delegator, features, items, featureOrder, 0); } catch (Exception e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } if (tree == null || tree.size() == 0) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resource,"productservices.feature_grouping_came_back_empty", locale)); } else { result.put("variantTree", tree); result.put("virtualVariant", virtualVariant); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } Map sample = null; try { sample = makeVariantSample(dctx.getDelegator(), features, items, (String) featureOrder.get(0)); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); } if (sample == null || sample.size() == 0) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resource,"productservices.feature_sample_came_back_empty", locale)); } else { result.put("variantSample", sample); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } return result; } /** * Gets the product features of a product. */ public static Map prodGetFeatures(DispatchContext dctx, Map context) { // * String productId -- Product ID to fond // * String type -- Type of feature (STANDARD_FEATURE, SELECTABLE_FEATURE) // * String distinct -- Distinct feature (SIZE, COLOR) GenericDelegator delegator = dctx.getDelegator(); Map result = new HashMap(); String productId = (String) context.get("productId"); String distinct = (String) context.get("distinct"); String type = (String) context.get("type"); Locale locale = (Locale) context.get("locale"); String errMsg=null; Collection features = null; try { Map fields = UtilMisc.toMap("productId", productId); List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); if (distinct != null) fields.put("productFeatureTypeId", distinct); if (type != null) fields.put("productFeatureApplTypeId", type); features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order); result.put("productFeatures", features); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errMessage", e.toString()); errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_feature_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); } return result; } /** * Finds a product by product ID. */ public static Map prodFindProduct(DispatchContext dctx, Map context) { // * String productId -- Product ID to find GenericDelegator delegator = dctx.getDelegator(); Map result = new HashMap(); String productId = (String) context.get("productId"); Locale locale = (Locale) context.get("locale"); String errMsg = null; if (productId == null || productId.length() == 0) { errMsg = UtilProperties.getMessage(resource,"productservices.invalid_productId_passed", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } try { GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); GenericValue mainProduct = product; if (product.get("isVariant") != null && product.getString("isVariant").equalsIgnoreCase("Y")) { List c = product.getRelatedByAndCache("AssocProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT")); if (c != null) { //if (Debug.infoOn()) Debug.logInfo("Found related: " + c, module); c = EntityUtil.filterByDate(c, true); //if (Debug.infoOn()) Debug.logInfo("Found Filtered related: " + c, module); if (c.size() > 0) { GenericValue asV = (GenericValue) c.iterator().next(); //if (Debug.infoOn()) Debug.logInfo("ASV: " + asV, module); mainProduct = asV.getRelatedOneCache("MainProduct"); //if (Debug.infoOn()) Debug.logInfo("Main product = " + mainProduct, module); } } } result.put("product", mainProduct); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { e.printStackTrace(); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); } return result; } /** * Finds associated products by product ID and association ID. */ public static Map prodFindAssociatedByType(DispatchContext dctx, Map context) { // * String productId -- Current Product ID // * String type -- Type of association (ie PRODUCT_UPGRADE, PRODUCT_COMPLEMENT, PRODUCT_VARIANT) GenericDelegator delegator = dctx.getDelegator(); Map result = new HashMap(); String productId = (String) context.get("productId"); String productIdTo = (String) context.get("productIdTo"); String type = (String) context.get("type"); Locale locale = (Locale) context.get("locale"); String errMsg = null; Boolean cvaBool = (Boolean) context.get("checkViewAllow"); boolean checkViewAllow = (cvaBool == null ? false : cvaBool.booleanValue()); String prodCatalogId = (String) context.get("prodCatalogId"); if (productId == null && productIdTo == null) { errMsg = UtilProperties.getMessage(resource,"productservices.both_productId_and_productIdTo_cannot_be_null", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } if (productId != null && productIdTo != null) { errMsg = UtilProperties.getMessage(resource,"productservices.both_productId_and_productIdTo_cannot_be_defined", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } productId = productId == null ? productIdTo : productId; GenericValue product = null; try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"productservices.productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } if (product == null) { errMsg = UtilProperties.getMessage(resource,"productservices.problems_getting_product_entity", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } try { List productAssocs = null; if (productIdTo == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -