📄 productevents.java
字号:
} } catch (GenericTransactionException gte) { String errMsg = "Error updating quick admin selectable feature settings: " + gte.toString(); Debug.logError(gte, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } return "success"; } protected static void checkUpdateFeatureApplByDescription(String productId, GenericValue product, String description, String productFeatureTypeId, GenericValue productFeatureType, String productFeatureApplTypeId, Timestamp nowTimestamp, GenericDelegator delegator, Set descriptionsToRemove, Set descriptionsRemoved) throws GenericEntityException { if (productFeatureType == null) { return; } GenericValue productFeatureAndAppl = null; Set descriptionsForThisType = new HashSet(); List productFeatureAndApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureTypeId", productFeatureTypeId)), true); if (productFeatureAndApplList.size() > 0) { Iterator productFeatureAndApplIter = productFeatureAndApplList.iterator(); while (productFeatureAndApplIter.hasNext()) { productFeatureAndAppl = (GenericValue) productFeatureAndApplIter.next(); GenericValue productFeatureAppl = delegator.makeValidValue("ProductFeatureAppl", productFeatureAndAppl); // remove productFeatureAppl IFF: productFeatureAppl != null && (description is empty/null || description is different than existing) if (productFeatureAppl != null && (description == null || !description.equals(productFeatureAndAppl.getString("description")))) { // if descriptionsToRemove is not null, only remove if description is in that set if (descriptionsToRemove == null || (descriptionsToRemove != null && descriptionsToRemove.contains(productFeatureAndAppl.get("description")))) { // okay, almost there: before removing it if this is a virtual product check to make SURE this feature's description doesn't exist on any of the variants; wouldn't want to remove something we should have kept around... if ("Y".equals(product.getString("isVirtual"))) { boolean foundFeatureOnVariant = false; // get/check all the variants List variantAssocs = product.getRelatedByAnd("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT")); List variants = EntityUtil.getRelated("AssocProduct", variantAssocs); Iterator variantIter = variants.iterator(); while (!foundFeatureOnVariant && variantIter.hasNext()) { GenericValue variant = (GenericValue) variantIter.next(); // get the selectable features for the variant List variantProductFeatureAndAppls = variant.getRelated("ProductFeatureAndAppl", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "productFeatureApplTypeId", "STANDARD_FEATURE", "description", description), null); if (variantProductFeatureAndAppls.size() > 0) { foundFeatureOnVariant = true; } } if (foundFeatureOnVariant) { // don't remove this one! continue; } } if (descriptionsRemoved != null) { descriptionsRemoved.add(productFeatureAndAppl.get("description")); } productFeatureAppl.remove(); continue; } } // we got here, is still a valid description associated with this product descriptionsForThisType.add(productFeatureAndAppl.get("description")); } } if (description != null && (productFeatureAndAppl == null || (productFeatureAndAppl != null && !descriptionsForThisType.contains(description)))) { // need to add an appl, and possibly the feature // see if a feature exists with the type and description specified (if doesn't exist will create later) String productFeatureId = null; List existingProductFeatureList = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "description", description)); if (existingProductFeatureList.size() > 0) { GenericValue existingProductFeature = (GenericValue) existingProductFeatureList.get(0); productFeatureId = existingProductFeature.getString("productFeatureId"); } else { // doesn't exist, so create it productFeatureId = delegator.getNextSeqId("ProductFeature").toString(); GenericValue newProductFeature = delegator.makeValue("ProductFeature", UtilMisc.toMap("productFeatureId", productFeatureId, "productFeatureTypeId", productFeatureTypeId, "description", description)); // if there is a productFeatureCategory with the same id as the productFeatureType, use that category. // otherwise, create a category for the feature type if (delegator.findByPrimaryKey("ProductFeatureCategory", UtilMisc.toMap("productFeatureCategoryId", productFeatureTypeId)) == null) { GenericValue productFeatureCategory = delegator.makeValue("ProductFeatureCategory", null); productFeatureCategory.set("productFeatureCategoryId", productFeatureTypeId); productFeatureCategory.set("description", productFeatureType.get("description")); productFeatureCategory.create(); } newProductFeature.set("productFeatureCategoryId", productFeatureTypeId); newProductFeature.create(); } // check to see if the productFeatureId is already attached to the virtual or variant, if not attach them... List specificProductFeatureApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureId", productFeatureId)), true); if (specificProductFeatureApplList.size() == 0) { delegator.create("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId, "productFeatureApplTypeId", productFeatureApplTypeId, "fromDate", nowTimestamp)); } } } public static String removeFeatureApplsByFeatureTypeId(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); //Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); //GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); String productId = request.getParameter("productId"); String productFeatureTypeId = request.getParameter("productFeatureTypeId"); try { GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); // get all the variants List variantAssocs = product.getRelatedByAnd("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT")); List variants = EntityUtil.getRelated("AssocProduct", variantAssocs); Iterator variantIter = variants.iterator(); while (variantIter.hasNext()) { GenericValue variant = (GenericValue) variantIter.next(); // get the selectable features for the variant List productFeatureAndAppls = variant.getRelated("ProductFeatureAndAppl", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "productFeatureApplTypeId", "STANDARD_FEATURE"), null); Iterator productFeatureAndApplIter = productFeatureAndAppls.iterator(); while (productFeatureAndApplIter.hasNext()) { GenericValue productFeatureAndAppl = (GenericValue) productFeatureAndApplIter.next(); GenericPK productFeatureApplPK = delegator.makePK("ProductFeatureAppl", null); productFeatureApplPK.setPKFields(productFeatureAndAppl); delegator.removeByPrimaryKey(productFeatureApplPK); } } List productFeatureAndAppls = product.getRelated("ProductFeatureAndAppl", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"), null); Iterator productFeatureAndApplIter = productFeatureAndAppls.iterator(); while (productFeatureAndApplIter.hasNext()) { GenericValue productFeatureAndAppl = (GenericValue) productFeatureAndApplIter.next(); GenericPK productFeatureApplPK = delegator.makePK("ProductFeatureAppl", null); productFeatureApplPK.setPKFields(productFeatureAndAppl); delegator.removeByPrimaryKey(productFeatureApplPK); } } catch (GenericEntityException e) { String errMsg = "Error creating new virtual product from variant products: " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } return "success"; } public static String removeProductFeatureAppl(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); //Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); //GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); String productId = request.getParameter("productId"); String productFeatureId = request.getParameter("productFeatureId"); if (UtilValidate.isEmpty(productId) || UtilValidate.isEmpty(productFeatureId)) { String errMsg = "Must specify both a productId [was:" + productId + "] and a productFeatureId [was:" + productFeatureId + "] to remove the feature from the product."; request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } try { delegator.removeByAnd("ProductFeatureAppl", UtilMisc.toMap("productFeatureId", productFeatureId, "productId", productId)); } catch (GenericEntityException e) { String errMsg = "Error removing product feature: " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } return "success"; } public static String addProductToCategories(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); String productId = request.getParameter("productId"); String fromDate = request.getParameter("fromDate"); if ((fromDate == null) || (fromDate.trim().length() == 0)) { fromDate = UtilDateTime.nowTimestamp().toString(); } String[] categoryId = request.getParameterValues("categoryId"); if (categoryId != null) { for (int i = 0; i < categoryId.length; i++) { try { List catMembs = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap( "productCategoryId", categoryId[i], "productId", productId)); catMembs = EntityUtil.filterByDate(catMembs); if (catMembs.size() == 0) { delegator.create("ProductCategoryMember", UtilMisc.toMap("productCategoryId", categoryId[i], "productId", productId, "fromDate", fromDate)); } } catch (GenericEntityException e) { String errMsg = "Error adding to category: " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } } return "success"; } public static String updateProductCategoryMember(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); String productId = request.getParameter("productId"); String productCategoryId = request.getParameter("productCategoryId"); String thruDate = request.getParameter("thruDate"); if ((thruDate == null) || (thruDate.trim().length() == 0)) { thruDate = UtilDateTime.nowTimestamp().toString(); } try { List prodCatMembs = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId)); prodCatMembs = EntityUtil.filterByDate(prodCatMembs); if (prodCatMembs.size() > 0) { // there is one to modify GenericValue prodCatMemb = (GenericValue)prodCatMembs.get(0); prodCatMemb.setString("thruDate", thruDate); prodCatMemb.store(); } } catch (GenericEntityException e) { String errMsg = "Error adding to category: " + e.t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -