📄 productdetail.bsh
字号:
// Special Variant Code if ("Y".equals(product.getString("isVirtual"))) { featureMap = dispatcher.runSync("getProductFeatureSet", UtilMisc.toMap("productId", productId)); featureSet = featureMap.get("featureSet"); if (featureSet != null && featureSet.size() > 0) { variantTreeMap = dispatcher.runSync("getProductVariantTree", UtilMisc.toMap("productId", productId, "featureOrder", featureSet, "productStoreId", productStoreId)); variantTree = variantTreeMap.get("variantTree"); imageMap = variantTreeMap.get("variantSample"); virtualVariant = variantTreeMap.get("virtualVariant"); context.put("virtualVariant", virtualVariant); if (variantTree != null) { context.put("variantTree", variantTree); context.put("variantTreeSize", new Integer(variantTree.size())); } if (imageMap != null) { context.put("variantSample", imageMap); context.put("variantSampleKeys", imageMap.keySet()); context.put("variantSampleSize", new Integer(imageMap.size())); } context.put("featureSet", featureSet); if (variantTree != null && variantTree.size() > 0) { featureOrder = new LinkedList(featureSet); foi = featureOrder.iterator(); while (foi.hasNext()) { featureKey = foi.next(); featureValue = delegator.findByPrimaryKeyCache("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", featureKey)); fValue = featureValue.get("description") != null ? featureValue.getString("description") : featureValue.getString("productFeatureTypeId"); featureTypes.put(featureKey, fValue); } } context.put("featureTypes", featureTypes); context.put("featureOrder", featureOrder); if (featureOrder.size() > 0) { context.put("featureOrderFirst", featureOrder.get(0)); } if (variantTree != null && imageMap != null) { jsBuf = new StringBuffer(); jsBuf.append("<script language=\"JavaScript\">"); jsBuf.append("var DET = new Array(" + variantTree.size() + ");"); jsBuf.append("var IMG = new Array(" + variantTree.size() + ");"); jsBuf.append("var OPT = new Array(" + featureOrder.size() + ");"); jsBuf.append("var VIR = new Array(" + virtualVariant.size() + ");"); jsBuf.append("var detailImageUrl = null;"); for (li = 0; li < featureOrder.size(); li++) { jsBuf.append("OPT[" + li + "] = \"FT" + featureOrder.get(li) + "\";"); } for (li = 0; li < virtualVariant.size(); li++) { jsBuf.append("VIR[" + li + "] = \"" + virtualVariant.get(li) + "\";"); } // build the top level topLevelName = featureOrder.get(0); jsBuf.append("function list" + topLevelName + "() {"); jsBuf.append("document.forms[\"addform\"].elements[\"FT" + topLevelName + "\"].options.length = 1;"); jsBuf.append("document.forms[\"addform\"].elements[\"FT" + topLevelName + "\"].options[0] = new Option(\"" + featureTypes.get(topLevelName) + "\",\"\",true,true);"); if (variantTree != null) { vTreeKeySet = variantTree.keySet(); vti = vTreeKeySet.iterator(); firstDetailImage = null; firstLargeImage = null; counter = 0; while (vti.hasNext()) { key = vti.next(); value = variantTree.get(key); opt = null; if (featureOrder.size() == 1) { opt = value.iterator().next(); } else { opt = "" + counter; } // create the variant content wrapper contentWrapper = new ProductContentWrapper(((GenericValue) imageMap.get(key)), request); // get the default image virtualDetailImage = productContentWrapper.get("DETAIL_IMAGE_URL"); virtualLargeImage = productContentWrapper.get("LARGE_IMAGE_URL"); // initial image paths detailImage = contentWrapper.get("DETAIL_IMAGE_URL"); largeImage = contentWrapper.get("LARGE_IMAGE_URL"); if (detailImage == null || detailImage.length() == 0) { detailImage = virtualDetailImage; } if (largeImage == null || largeImage.length() == 0) { largeImage = virtualLargeImage; } // full image URLs detailImageUrl = null; largeImageUrl = null; // append the content prefix if (detailImage != null && detailImage.length() > 0) { detailImageUrl = ContentUrlTag.getContentPrefix(request) + detailImage; // base64 encode the image url for a little protection detailImageUrl = URLEncoder.encode(Base64.base64Encode(detailImageUrl), "UTF-8"); } if (largeImage != null && largeImage.length() > 0) { largeImageUrl = ContentUrlTag.getContentPrefix(request) + largeImage; } jsBuf.append("document.forms[\"addform\"].elements[\"FT" + topLevelName + "\"].options[" + (counter+1) + "] = new Option(\"" + key + "\",\"" + opt + "\");"); jsBuf.append("DET[" + counter + "] = \"" + detailImageUrl +"\";"); jsBuf.append("IMG[" + counter + "] = \"" + largeImageUrl +"\";"); if (firstDetailImage == null || firstDetailImage.length() == 0) { firstDetailImage = detailImageUrl; } if (firstLargeImage == null || firstLargeImage.length() == 0) { firstLargeImage = largeImage; } counter++; } context.put("firstDetailImage", firstDetailImage); context.put("firstLargeImage", firstLargeImage); } jsBuf.append("}"); // build dynamic lists if (variantTree != null) { topLevelKeys = variantTree.keySet(); tli = topLevelKeys.iterator(); topLevelKeysCt = 0; while (tli.hasNext()) { cnt = "" + topLevelKeysCt; varTree = variantTree.get(tli.next()); if (varTree instanceof Map) { jsBuf.append(buildNext(varTree, featureOrder, featureOrder.get(1), cnt, featureTypes)); } topLevelKeysCt++; } } // make a list of variant sku with requireAmount variantsRes = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productId", productId, "type", "PRODUCT_VARIANT", "checkViewAllow", Boolean.TRUE, "prodCatalogId", currentCatalogId)); variants = variantsRes.get("assocProducts"); if (variants != null) { amt = new StringBuffer(); amt.append("function checkAmtReq(sku) { "); vari = variants.iterator(); while (vari.hasNext()) { variantAssoc = vari.next(); variant = variantAssoc.getRelatedOne("AssocProduct"); amt.append(" if (sku == \"" + variant.get("productId") + "\") return \"" + (variant.get("requireAmount") != null ? variant.getString("requireAmount") : "N") + "\"; "); } amt.append(" } "); } jsBuf.append(amt.toString()); jsBuf.append("</script>"); context.put("virtualJavaScript", jsBuf.toString()); } } } // get product associations obsoleteProducts = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productId", productId, "type", "PRODUCT_OBSOLESCENCE", "checkViewAllow", Boolean.TRUE, "prodCatalogId", currentCatalogId)); context.put("obsoleteProducts", obsoleteProducts.get("assocProducts")); crossSellProducts = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productId", productId, "type", "PRODUCT_COMPLEMENT", "checkViewAllow", Boolean.TRUE, "prodCatalogId", currentCatalogId)); context.put("crossSellProducts", crossSellProducts.get("assocProducts")); upSellProducts = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productId", productId, "type", "PRODUCT_UPGRADE", "checkViewAllow", Boolean.TRUE, "prodCatalogId", currentCatalogId)); context.put("upSellProducts", upSellProducts.get("assocProducts")); obsolenscenseProducts = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productIdTo", productId, "type", "PRODUCT_OBSOLESCENCE", "checkViewAllow", Boolean.TRUE, "prodCatalogId", currentCatalogId)); context.put("obsolenscenseProducts", obsolenscenseProducts.get("assocProducts")); // get other cross-sell information: product with a common feature commonProductFeatureId = "SYMPTOM"; // does this product have that feature? commonProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", commonProductFeatureId), UtilMisc.toList("sequenceNum", "defaultSequenceNum")); if (commonProductFeatureAndAppls.size() > 0) { commonProductFeatureIds = EntityUtil.getFieldListFromEntityList(commonProductFeatureAndAppls, "productFeatureId", true); // now search for other products that have this feature visitId = VisitHandler.getVisitId(session); productSearchConstraintList = new LinkedList(); productSearchConstraintList.add(new ProductSearch.FeatureSetConstraint(commonProductFeatureIds)); // make sure the view allow category is included productSearchConstraintList = ProductSearchSession.ensureViewAllowConstraint(productSearchConstraintList, currentCatalogId, delegator); // don't care about the sort on this one resultSortOrder = null; commonFeatureResultIdsOrig = ProductSearch.searchProducts(productSearchConstraintList, resultSortOrder, delegator, visitId); commonFeatureResultIds = new LinkedList(); commonFeatureResultIdIter = commonFeatureResultIdsOrig.iterator(); while (commonFeatureResultIdIter.hasNext()) { commonFeatureResultId = commonFeatureResultIdIter.next(); // filter out the current product if (commonFeatureResultId.equals(productId)) { continue; } // filter out all variants commonProduct = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", commonFeatureResultId)); if (commonProduct == null || ("Y".equals(commonProduct.getString("isVariant")))) { continue; } commonFeatureResultIds.add(commonFeatureResultId); } if (commonFeatureResultIds.size() > 0) { context.put("commonFeatureResultIds", commonFeatureResultIds); } } // get the DIGITAL_DOWNLOAD related Content records to show the contentName/description downloadProductContentAndInfoList = delegator.findByAndCache("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "productContentTypeId", "DIGITAL_DOWNLOAD")); context.put("downloadProductContentAndInfoList", downloadProductContentAndInfoList); // not the best to save info in an action, but this is probably the best place to count a view; it is done async dispatcher.runAsync("countProductView", UtilMisc.toMap("productId", productId, "weight", new Long(1)), false);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -