Author: lektran
Date: Sat Jul 12 02:31:11 2008 New Revision: 676137 URL: http://svn.apache.org/viewvc?rev=676137&view=rev Log: A few more bsh -> groovy conversions Added: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy - copied, changed from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy - copied, changed from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy - copied, changed from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy - copied, changed from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh Removed: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh Modified: ofbiz/trunk/applications/ecommerce/widget/CatalogScreens.xml ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/Product.groovy ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml Modified: ofbiz/trunk/applications/ecommerce/widget/CatalogScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/ecommerce/widget/CatalogScreens.xml?rev=676137&r1=676136&r2=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/ecommerce/widget/CatalogScreens.xml (original) +++ ofbiz/trunk/applications/ecommerce/widget/CatalogScreens.xml Sat Jul 12 02:31:11 2008 @@ -50,7 +50,7 @@ <actions> <!--<script location="component://ecommerce/webapp/ecommerce/WEB-INF/actions/catalog/sidedeepcategory.bsh"/>--> <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://ecommerce/webapp/ecommerce/catalog/sidedeepcategory.ftl"/></html></platform-specific> @@ -82,7 +82,7 @@ <section> <actions> <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://ecommerce/webapp/ecommerce/catalog/minilastviewedcategories.ftl"/></html></platform-specific> @@ -133,7 +133,7 @@ <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="EcommerceUiLabels" map-name="uiLabelMap" global="true"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://order/webapp/ordermgr/entry/catalog/productsummary.ftl"/></html></platform-specific> @@ -261,7 +261,7 @@ <actions> <set field="productsummaryScreen" value="component://ecommerce/widget/CatalogScreens.xml#productsummary"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy"/> </actions> <widgets> <include-screen name="breadcrumbs"/> @@ -275,7 +275,7 @@ <actions> <set field="productsummaryScreen" value="component://ecommerce/widget/CatalogScreens.xml#productsummary"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy"/> <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/PrepareConfigForm.groovy"/> </actions> <widgets> @@ -355,7 +355,7 @@ <set field="quickaddsummaryScreen" value="component://ecommerce/widget/CatalogScreens.xml#quickaddsummary"/> <set field="titleProperty" value="PageTitleQuickAdd"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy"/> </actions> <widgets> <decorator-screen name="main-decorator" location="${parameters.mainDecoratorLocation}"> @@ -370,7 +370,7 @@ <screen name="quickaddsummary"> <section> <actions> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://order/webapp/ordermgr/entry/catalog/quickaddsummary.ftl"/></html></platform-specific> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/Product.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/Product.groovy?rev=676137&r1=676136&r2=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/Product.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/Product.groovy Sat Jul 12 02:31:11 2008 @@ -86,7 +86,9 @@ members = delegator.findByAndCache("ProductCategoryMember", [productId : productId]); members.each { member -> category = member.getRelatedOneCache("ProductCategory"); - keywords.add(category.description); + if (category.description) { + keywords.add(category.description); + } } context.metaKeywords = StringUtil.join(keywords, ", "); Copied: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy (from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh) URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy?p2=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy&p1=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh&r1=675904&r2=676137&rev=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy Sat Jul 12 02:31:11 2008 @@ -40,16 +40,12 @@ import org.ofbiz.order.shoppingcart.ShoppingCartEvents; String buildNext(Map map, List order, String current, String prefix, Map featureTypes) { - keySet = map.keySet(); ct = 0; - i = keySet.iterator(); buf = new StringBuffer(); buf.append("function listFT" + current + prefix + "() { "); buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options.length = 1;"); - buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options[0] = new Option(\"" + featureTypes.get(current) + "\",\"\",true,true);"); - while (i.hasNext()) { - key = i.next(); - value = map.get(key); + buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options[0] = new Option(\"" + featureTypes.current + "\",\"\",true,true);"); + map.each { key, value -> optValue = null; if (order.indexOf(current) == (order.size()-1)) { @@ -63,12 +59,9 @@ } buf.append(" }"); if (order.indexOf(current) < (order.size()-1)) { - i2 = keySet.iterator(); ct = 0; - while (i2.hasNext()) { + map.each { key, value -> nextOrder = order.get(order.indexOf(current)+1); - key = i2.next(); - value = map.get(key); newPrefix = prefix + "_" + ct; buf.append(buildNext(value, order, nextOrder, newPrefix, featureTypes)); ct++; @@ -80,31 +73,31 @@ cart = ShoppingCartEvents.getCartObject(request); // get the shopping lists for the user (if logged in) -if (userLogin != null) { - exprList = UtilMisc.toList(EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, userLogin.getString("partyId")), - EntityCondition.makeCondition("listName", EntityOperator.NOT_EQUAL, "auto-save")); +if (userLogin) { + exprList = [EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, userLogin.partyId), + EntityCondition.makeCondition("listName", EntityOperator.NOT_EQUAL, "auto-save")]; condition = EntityCondition.makeCondition(exprList, EntityOperator.AND); - allShoppingLists = delegator.findList("ShoppingList", condition, null, UtilMisc.toList("listName"), null, false); - context.put("shoppingLists", allShoppingLists); + allShoppingLists = delegator.findList("ShoppingList", condition, null, ["listName"], null, false); + context.shoppingLists = allShoppingLists; } // set the content path prefix contentPathPrefix = CatalogWorker.getContentPathPrefix(request); -context.put("contentPathPrefix", contentPathPrefix); +context.contentPathPrefix = contentPathPrefix; // get the product detail information -if (product != null) { - productId = product.getString("productId"); - context.put("product_id", productId); - productTypeId = product.getString("productTypeId"); - featureTypes = new HashMap(); - featureOrder = new LinkedList(); +if (product) { + productId = product.productId; + context.product_id = productId; + productTypeId = product.productTypeId; + featureTypes = [:]; + featureOrder = []; // set this as a last viewed - int LAST_VIEWED_TO_KEEP = 10; // modify this to change the number of last viewed to keep + LAST_VIEWED_TO_KEEP = 10; // modify this to change the number of last viewed to keep lastViewedProducts = session.getAttribute("lastViewedProducts"); - if (lastViewedProducts == null) { - lastViewedProducts = new LinkedList(); + if (!lastViewedProducts) { + lastViewedProducts = []; session.setAttribute("lastViewedProducts", lastViewedProducts); } lastViewedProducts.remove(productId); @@ -114,58 +107,50 @@ } // make the productContentWrapper - ProductContentWrapper productContentWrapper = new ProductContentWrapper(product, request); - context.put("productContentWrapper", productContentWrapper); + productContentWrapper = new ProductContentWrapper(product, request); + context.productContentWrapper = productContentWrapper; // get the main detail image (virtual or single product) mainDetailImage = productContentWrapper.get("DETAIL_IMAGE_URL"); - if (mainDetailImage != null && mainDetailImage.length() > 0) { + if (mainDetailImage) { mainDetailImageUrl = ContentUrlTag.getContentPrefix(request) + mainDetailImage; mainDetailImageUrl = URLEncoder.encode(Base64.base64Encode(mainDetailImage), "UTF-8"); - context.put("mainDetailImageUrl", mainDetailImageUrl); + context.mainDetailImageUrl = mainDetailImageUrl; } // get next/previous information for category - categoryId = parameters.get("category_id"); - if (categoryId == null) categoryId = product.getString("primaryProductCategoryId"); - if (categoryId != null) context.put("categoryId", categoryId); - - Map catNextPreviousResult = null; - if (!UtilValidate.isEmpty(categoryId)) { - prevNextMap = UtilMisc.toMap("categoryId", categoryId, "productId", productId); - if (context.get("orderByFields") != null) { - prevNextMap.put("orderByFields", context.get("orderByFields")); - } else { - prevNextMap.put("orderByFields", UtilMisc.toList("sequenceNum", "productId")); - } + categoryId = parameters.category_id ?: product.primaryProductCategoryId; + if (categoryId) context.categoryId = categoryId; + + catNextPreviousResult = null; + if (categoryId) { + prevNextMap = [categoryId : categoryId, productId : productId]; + prevNextMap.orderByFields = context.orderByFields ?: ["sequenceNum", "productId"]; catNextPreviousResult = dispatcher.runSync("getPreviousNextProducts", prevNextMap); if (ServiceUtil.isError(catNextPreviousResult)) { - request.setAttribute("errorMessageList", UtilMisc.toList(ServiceUtil.getErrorMessage(catNextPreviousResult))); + request.setAttribute("errorMessageList", [ServiceUtil.getErrorMessage(catNextPreviousResult)]); return; } - if (catNextPreviousResult != null && catNextPreviousResult.get("category") != null) { - context.put("category", catNextPreviousResult.get("category")); - context.put("previousProductId", catNextPreviousResult.get("previousProductId")); - context.put("nextProductId", catNextPreviousResult.get("nextProductId")); + if (catNextPreviousResult && catNextPreviousResult.category) { + context.category = catNextPreviousResult.category; + context.previousProductId = catNextPreviousResult.previousProductId; + context.nextProductId = catNextPreviousResult.nextProductId; } } // get the product store productStore = ProductStoreWorker.getProductStore(request); - productStoreId = productStore.getString("productStoreId"); - context.put("productStoreId", productStoreId); + productStoreId = productStore.productStoreId; + context.productStoreId = productStoreId; // get a defined survey productSurvey = ProductStoreWorker.getProductSurveys(delegator, productStoreId, productId, "CART_ADD"); - if (productSurvey != null && productSurvey.size() > 0) { + if (productSurvey) { survey = EntityUtil.getFirst(productSurvey); surveyContext = UtilHttp.getParameterMap(request); - surveyPartyId = null; - if (userLogin != null) { - surveyPartyId = userLogin.getString("partyId"); - } - ProductStoreSurveyWrapper wrapper = new ProductStoreSurveyWrapper(survey, surveyPartyId, surveyContext); - context.put("surveyWrapper", wrapper); + surveyPartyId = userLogin?.partyId; + wrapper = new ProductStoreSurveyWrapper(survey, surveyPartyId, surveyContext); + context.surveyWrapper = wrapper; } // get the product price @@ -175,274 +160,248 @@ autoUserLogin = request.getSession().getAttribute("autoUserLogin"); if (cart.isSalesOrder()) { // sales order: run the "calculateProductPrice" service - priceContext = UtilMisc.toMap("product", product, "prodCatalogId", catalogId, - "currencyUomId", cart.getCurrency(), "autoUserLogin", autoUserLogin); - priceContext.put("webSiteId", webSiteId); - priceContext.put("productStoreId", productStoreId); - priceContext.put("checkIncludeVat", "Y"); - priceContext.put("agreementId", cart.getAgreementId()); - priceContext.put("partyId", cart.getPartyId()); // IMPORTANT: must put this in, or price will be calculated for the CSR instead of the customer + priceContext = [product : product, prodCatalogId : catalogId, + currencyUomId : cart.getCurrency(), autoUserLogin : autoUserLogin]; + priceContext.webSiteId = webSiteId; + priceContext.productStoreId = productStoreId; + priceContext.checkIncludeVat = "Y"; + priceContext.agreementId = cart.getAgreementId(); + priceContext.partyId = cart.getPartyId(); // IMPORTANT: must put this in, or price will be calculated for the CSR instead of the customer priceMap = dispatcher.runSync("calculateProductPrice", priceContext); - context.put("priceMap", priceMap); + context.priceMap = priceMap; } else { // purchase order: run the "calculatePurchasePrice" service - priceContext = UtilMisc.toMap("product", product, "currencyUomId", cart.getCurrency(), - "partyId", cart.getPartyId(), "userLogin", userLogin); + priceContext = [product : product, currencyUomId : cart.getCurrency(), + partyId : cart.getPartyId(), userLogin : userLogin]; priceMap = dispatcher.runSync("calculatePurchasePrice", priceContext); - context.put("priceMap", priceMap); + context.priceMap = priceMap; } // get the product review(s) - reviewByAnd = UtilMisc.toMap("statusId", "PRR_APPROVED", "productStoreId", productStoreId); - reviews = product.getRelatedCache("ProductReview", reviewByAnd, UtilMisc.toList("-postedDateTime")); - context.put("productReviews", reviews); + reviewByAnd = [statusId : "PRR_APPROVED", productStoreId : productStoreId]; + reviews = product.getRelatedCache("ProductReview", reviewByAnd, ["-postedDateTime"]); + context.productReviews = reviews; // get the average rating - if (reviews != null && reviews.size() > 0) { - List ratingReviews = EntityUtil.filterByAnd(reviews, UtilMisc.toList(EntityCondition.makeCondition("productRating", EntityOperator.NOT_EQUAL, null))); - if (ratingReviews.size() > 0) { - context.put("averageRating", ProductWorker.getAverageProductRating(product, reviews, productStoreId)); - context.put("numRatings", ratingReviews.size()); + if (reviews) { + ratingReviews = EntityUtil.filterByAnd(reviews, [EntityCondition.makeCondition("productRating", EntityOperator.NOT_EQUAL, null)]); + if (ratingReviews) { + context.averageRating = ProductWorker.getAverageProductRating(product, reviews, productStoreId); + context.numRatings = ratingReviews.size(); } } // get the days to ship - facilityId = productStore.getString("inventoryFacilityId"); - /*productFacility = delegator.findByPrimaryKeyCache("ProductFacility", UtilMisc.toMap("productId", productId, "facilityId", facilityId)); - if (productFacility != null && productFacility.get("daysToShip") != null) { - context.put("daysToShip", productFacility.get("daysToShip")); - }*/ + facilityId = productStore.inventoryFacilityId; + /* + productFacility = delegator.findByPrimaryKeyCache("ProductFacility", [productId : productId, facilityId : facilityId); + context.daysToShip = productFacility?.daysToShip + */ - resultOutput = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.toMap("productId",productId, "facilityId", facilityId, "useCache", false)); - totalAvailableToPromise = resultOutput.get("availableToPromiseTotal"); - if(totalAvailableToPromise != null && totalAvailableToPromise.doubleValue() > 0) { - productFacility = delegator.findByPrimaryKeyCache("ProductFacility", UtilMisc.toMap("productId", productId, "facilityId", facilityId)); - if (productFacility != null && productFacility.get("daysToShip") != null) { - context.put("daysToShip", productFacility.get("daysToShip")); - } + resultOutput = dispatcher.runSync("getInventoryAvailableByFacility", [productId : productId, facilityId : facilityId, useCache : false]); + totalAvailableToPromise = resultOutput.availableToPromiseTotal; + if (totalAvailableToPromise) { + productFacility = delegator.findByPrimaryKeyCache("ProductFacility", [productId : productId, facilityId : facilityId]); + context.daysToShip = productFacility?.daysToShip } else { - supplierProducts=delegator.findByAndCache("SupplierProduct", UtilMisc.toMap("productId", productId),UtilMisc.toList("-availableFromDate")); + supplierProducts = delegator.findByAndCache("SupplierProduct", [productId : productId], ["-availableFromDate"]); supplierProduct = EntityUtil.getFirst(supplierProducts); - if (supplierProduct != null && supplierProduct.get("standardLeadTimeDays") != null) { - Double standardLeadTimeDays = supplierProduct.get("standardLeadTimeDays"); - double daysToShip = standardLeadTimeDays.doubleValue()+1; - context.put("daysToShip", new Double(daysToShip)); + if (supplierProduct?.standardLeadTimeDays) { + standardLeadTimeDays = supplierProduct.standardLeadTimeDays; + daysToShip = standardLeadTimeDays + 1; + context.daysToShip = daysToShip; } } // get the product distinguishing features - disFeatureMap = dispatcher.runSync("getProductFeatures", UtilMisc.toMap("productId", productId, "type", "DISTINGUISHING_FEAT")); - disFeatureList = disFeatureMap.get("productFeatures"); - context.put("disFeatureList", disFeatureList); - + disFeatureMap = dispatcher.runSync("getProductFeatures", [productId : productId, type : "DISTINGUISHING_FEAT"]); + disFeatureList = disFeatureMap.productFeatures; + context.disFeatureList = disFeatureList; + // an example of getting features of a certain type to show - sizeProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "SIZE"), UtilMisc.toList("sequenceNum", "defaultSequenceNum")); - context.put("sizeProductFeatureAndAppls", sizeProductFeatureAndAppls); + sizeProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", [productId : productId, productFeatureTypeId : "SIZE"], ["sequenceNum", "defaultSequenceNum"]); + context.sizeProductFeatureAndAppls = sizeProductFeatureAndAppls; // Special Variant Code - if ("Y".equals(product.getString("isVirtual"))) { + if ("Y".equals(product.isVirtual)) { if ("VV_FEATURETREE".equals(ProductWorker.getProductvirtualVariantMethod(delegator, productId))) { - context.put("featureLists", ProductWorker.getSelectableProductFeaturesByTypesAndSeq(product)); + context.featureLists = ProductWorker.getSelectableProductFeaturesByTypesAndSeq(product); } else { - 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); + featureMap = dispatcher.runSync("getProductFeatureSet", [productId : productId]); + featureSet = featureMap.featureSet; + if (featureSet) { + variantTreeMap = dispatcher.runSync("getProductVariantTree", [productId : productId, featureOrder : featureSet, productStoreId : productStoreId]); + variantTree = variantTreeMap.variantTree; + imageMap = variantTreeMap.variantSample; + virtualVariant = variantTreeMap.virtualVariant; + context.virtualVariant = virtualVariant; + if (variantTree) { + context.variantTree = variantTree; + context.variantTreeSize = variantTree.size(); + } + if (imageMap) { + context.variantSample = imageMap; + context.variantSampleKeys = imageMap.keySet(); + context.variantSampleSize = imageMap.size(); + } + context.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); + if (variantTree) { + featureOrder = new LinkedList(featureSet); + featureOrder.each { featureKey -> + featureValue = delegator.findByPrimaryKeyCache("ProductFeatureType", [productFeatureTypeId : featureKey]); + fValue = featureValue.get("description") ?: featureValue.productFeatureTypeId; + featureTypes[featureKey] = fValue; + } + } + context.featureTypes = featureTypes; + context.featureOrder = featureOrder; + if (featureOrder) { + context.featureOrderFirst = featureOrder[0]; } - } - 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() + ");"); + if (variantTree && imageMap) { + 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) + "\";"); + jsBuf.append("var detailImageUrl = null;"); + featureOrder.eachWithIndex { feature, i -> + jsBuf.append("OPT[" + i + "] = \"FT" + feature + "\";"); + } + virtualVariant.eachWithIndex { variant, i -> + jsBuf.append("VIR[" + i + "] = \"" + variant + "\";"); } - // 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; + // build the top level + topLevelName = featureOrder[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[topLevelName] + "\",\"\",true,true);"); + if (variantTree) { + firstDetailImage = null; + firstLargeImage = null; + counter = 0; + variantTree.each { key, value -> + opt = null; + if (featureOrder.size() == 1) { + opt = value.iterator().next(); + } else { + opt = counter as String; + } + // create the variant content wrapper + contentWrapper = new ProductContentWrapper(imageMap[key], request); + + // initial image paths + detailImage = contentWrapper.get("DETAIL_IMAGE_URL") ?: productContentWrapper.get("DETAIL_IMAGE_URL"); + largeImage = contentWrapper.get("LARGE_IMAGE_URL") ?: productContentWrapper.get("LARGE_IMAGE_URL"); + + // full image URLs + detailImageUrl = null; + largeImageUrl = null; + + // append the content prefix + if (detailImage) { + detailImageUrl = ContentUrlTag.getContentPrefix(request) + detailImage; + // base64 encode the image url for a little protection + detailImageUrl = URLEncoder.encode(Base64.base64Encode(detailImageUrl), "UTF-8"); + } + if (largeImage) { + 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) { + firstDetailImage = detailImageUrl; + } + if (!firstLargeImage) { + firstLargeImage = largeImage; + } + counter++; } - counter++; + context.firstDetailImage = firstDetailImage; + context.firstLargeImage = firstLargeImage; } - context.put("firstDetailImage", firstDetailImage); - context.put("firstLargeImage", firstLargeImage); - } - jsBuf.append("}"); + 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)); + // build dynamic lists + if (variantTree) { + variantTree.eachWithIndex { varTree, topLevelKeysCt -> + cnt = "" + topLevelKeysCt; + if (varTree instanceof Map) { + jsBuf.append(buildNext(varTree, featureOrder, featureOrder[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) { "); - // Create the javascript to return the price for each variant - variantPriceJS = new StringBuffer(); - variantPriceJS.append("function getVariantPrice(sku) { "); - // Format to apply the currency code to the variant price in the javascript - String localeString = productStore.getString("defaultLocaleString"); - if (UtilValidate.isNotEmpty(localeString)) { - locale = UtilMisc.parseLocale(localeString); - } - numberFormat = NumberFormat.getCurrencyInstance(locale); - vari = variants.iterator(); - while (vari.hasNext()) { - variantAssoc = vari.next(); - variant = variantAssoc.getRelatedOne("AssocProduct"); - // Get the price for each variant. Reuse the priceContext already setup for virtual product above and replace the product - if (cart.isSalesOrder()) { - // sales order: run the "calculateProductPrice" service - priceContext.put("product", variant); - variantPriceMap = dispatcher.runSync("calculateProductPrice", priceContext); + // make a list of variant sku with requireAmount + variantsRes = dispatcher.runSync("getAssociatedProducts", [productId : productId, type : "PRODUCT_VARIANT", checkViewAllow : true, prodCatalogId : currentCatalogId]); + variants = variantsRes.assocProducts; + if (variants) { + amt = new StringBuffer(); + amt.append("function checkAmtReq(sku) { "); + // Create the javascript to return the price for each variant + variantPriceJS = new StringBuffer(); + variantPriceJS.append("function getVariantPrice(sku) { "); + // Format to apply the currency code to the variant price in the javascript + localeString = productStore.defaultLocaleString; + if (localeString) { + locale = UtilMisc.parseLocale(localeString); + } + numberFormat = NumberFormat.getCurrencyInstance(locale); + variants.each { variantAssoc -> + variant = variantAssoc.getRelatedOne("AssocProduct"); + // Get the price for each variant. Reuse the priceContext already setup for virtual product above and replace the product + if (cart.isSalesOrder()) { + // sales order: run the "calculateProductPrice" service + priceContext.product = variant; + variantPriceMap = dispatcher.runSync("calculateProductPrice", priceContext); + } + amt.append(" if (sku == \"" + variant.productId + "\") return \"" + (variant.requireAmount ?: "N") + "\"; "); + variantPriceJS.append(" if (sku == \"" + variant.productId + "\") return \"" + numberFormat.format(variantPriceMap.basePrice) + "\"; "); } - amt.append(" if (sku == \"" + variant.get("productId") + "\") return \"" + (variant.get("requireAmount") != null ? variant.getString("requireAmount") : "N") + "\"; "); - variantPriceJS.append(" if (sku == \"" + variant.get("productId") + "\") return \"" + numberFormat.format(variantPriceMap.get("basePrice")) + "\"; "); + amt.append(" } "); + variantPriceJS.append(" } "); } - amt.append(" } "); - variantPriceJS.append(" } "); - } - jsBuf.append(amt.toString()); - jsBuf.append(variantPriceJS.toString()); - jsBuf.append("</script>"); + jsBuf.append(amt.toString()); + jsBuf.append(variantPriceJS.toString()); + jsBuf.append("</script>"); - context.put("virtualJavaScript", jsBuf.toString()); + context.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")); + obsoleteProducts = dispatcher.runSync("getAssociatedProducts", [productId : productId, type : "PRODUCT_OBSOLESCENCE", checkViewAllow : true, prodCatalogId : currentCatalogId]); + context.obsoleteProducts = obsoleteProducts.assocProducts; + crossSellProducts = dispatcher.runSync("getAssociatedProducts", [productId : productId, type : "PRODUCT_COMPLEMENT", checkViewAllow : true, prodCatalogId : currentCatalogId]); + context.crossSellProducts = crossSellProducts.assocProducts; + + upSellProducts = dispatcher.runSync("getAssociatedProducts", [productId : productId, type : "PRODUCT_UPGRADE", checkViewAllow : true, prodCatalogId : currentCatalogId]); + context.upSellProducts = upSellProducts.assocProducts; + + obsolenscenseProducts = dispatcher.runSync("getAssociatedProducts", [productIdTo : productId, type : "PRODUCT_OBSOLESCENCE", checkViewAllow : true, prodCatalogId : currentCatalogId]); + context.obsolenscenseProducts = obsolenscenseProducts.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) { + commonProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", [productId : productId, productFeatureTypeId : commonProductFeatureId], ["sequenceNum", "defaultSequenceNum"]); + if (commonProductFeatureAndAppls) { commonProductFeatureIds = EntityUtil.getFieldListFromEntityList(commonProductFeatureAndAppls, "productFeatureId", true); - + // now search for other products that have this feature visitId = VisitHandler.getVisitId(session); - productSearchConstraintList = new LinkedList(); + productSearchConstraintList = []; productSearchConstraintList.add(new ProductSearch.FeatureSetConstraint(commonProductFeatureIds)); // make sure the view allow category is included productSearchConstraintList = ProductSearchSession.ensureViewAllowConstraint(productSearchConstraintList, currentCatalogId, delegator); @@ -451,7 +410,7 @@ resultSortOrder = null; commonFeatureResultIdsOrig = ProductSearch.searchProducts(productSearchConstraintList, resultSortOrder, delegator, visitId); - commonFeatureResultIds = new LinkedList(); + commonFeatureResultIds = []; commonFeatureResultIdIter = commonFeatureResultIdsOrig.iterator(); while (commonFeatureResultIdIter.hasNext()) { commonFeatureResultId = commonFeatureResultIdIter.next(); @@ -460,21 +419,21 @@ continue; } // filter out all variants - commonProduct = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", commonFeatureResultId)); - if (commonProduct == null || ("Y".equals(commonProduct.getString("isVariant")))) { + commonProduct = delegator.findByPrimaryKeyCache("Product", [productId : commonFeatureResultId]); + if ("Y".equals(commonProduct?.isVariant)) { continue; } commonFeatureResultIds.add(commonFeatureResultId); } - if (commonFeatureResultIds.size() > 0) { - context.put("commonFeatureResultIds", commonFeatureResultIds); + if (commonFeatureResultIds) { + context.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); + downloadProductContentAndInfoList = delegator.findByAndCache("ProductContentAndInfo", [productId : productId, productContentTypeId : "DIGITAL_DOWNLOAD"]); + context.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); + dispatcher.runAsync("countProductView", [productId : productId, weight : new Long(1)], false); } Copied: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy (from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh) URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy?p2=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy&p1=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh&r1=675904&r2=676137&rev=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy Sat Jul 12 02:31:11 2008 @@ -36,125 +36,111 @@ //either optProduct, optProductId or productId must be specified product = request.getAttribute("optProduct"); optProductId = request.getAttribute("optProductId"); -productId = request.getAttribute("productId"); +productId = product?.productId ?: optProductId ?: request.getAttribute("productId"); webSiteId = CatalogWorker.getWebSiteId(request); catalogId = CatalogWorker.getCurrentCatalogId(request); productStore = ProductStoreWorker.getProductStore(request); -facilityId = productStore.getString("inventoryFacilityId"); -productStoreId = productStore.getString("productStoreId"); +facilityId = productStore.inventoryFacilityId; +productStoreId = productStore.productStoreId; autoUserLogin = session.getAttribute("autoUserLogin"); userLogin = session.getAttribute("userLogin"); cart = ShoppingCartEvents.getCartObject(request); -context.put("nowTimestamp", UtilDateTime.nowTimestamp()); context.remove("daysToShip"); context.remove("averageRating"); context.remove("numRatings"); context.remove("totalPrice"); -if (product != null) { - productId = product.get("productId"); -} -if (optProductId != null) { - productId = optProductId; -} - // get the product entity -if (product == null && productId != null) { - product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); +if (!product && productId) { + product = delegator.findByPrimaryKeyCache("Product", [productId : productId]); } -if (product != null) { - resultOutput = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.toMap("productId",product.get("productId"), "facilityId", facilityId, "useCache", true)); - totalAvailableToPromise = resultOutput.get("availableToPromiseTotal"); - if(totalAvailableToPromise != null && totalAvailableToPromise.doubleValue() > 0) { - productFacility = delegator.findByPrimaryKeyCache("ProductFacility", UtilMisc.toMap("productId", product.get("productId"), "facilityId", facilityId)); - if (productFacility != null && productFacility.get("daysToShip") != null) { - context.put("daysToShip", productFacility.get("daysToShip")); - } +if (product) { + resultOutput = dispatcher.runSync("getInventoryAvailableByFacility", [productId : product.productId, facilityId : facilityId, useCache : true]); + totalAvailableToPromise = resultOutput.availableToPromiseTotal; + if (totalAvailableToPromise && totalAvailableToPromise.doubleValue() > 0) { + productFacility = delegator.findByPrimaryKeyCache("ProductFacility", [productId : product.productId, facilityId : facilityId]); + if (productFacility?.daysToShip != null) { + context.daysToShip = productFacility.daysToShip; + } } else { - supplierProducts=delegator.findByAndCache("SupplierProduct", UtilMisc.toMap("productId", product.get("productId")),UtilMisc.toList("-availableFromDate")); + supplierProducts = delegator.findByAndCache("SupplierProduct", [productId : product.productId], ["-availableFromDate"]); supplierProduct = EntityUtil.getFirst(supplierProducts); - if (supplierProduct != null && supplierProduct.get("standardLeadTimeDays") != null) { - Double standardLeadTimeDays = supplierProduct.get("standardLeadTimeDays"); - double daysToShip = standardLeadTimeDays.doubleValue()+1; - context.put("daysToShip", new Double(daysToShip)); + if (supplierProduct?.standardLeadTimeDays != null) { + standardLeadTimeDays = supplierProduct.standardLeadTimeDays; + daysToShip = standardLeadTimeDays + 1; + context.daysToShip = daysToShip; } } // make the productContentWrapper - ProductContentWrapper productContentWrapper = new ProductContentWrapper(product, request); - context.put("productContentWrapper", productContentWrapper); + productContentWrapper = new ProductContentWrapper(product, request); + context.productContentWrapper = productContentWrapper; } categoryId = null; reviews = null; -if (product != null) { - categoryId = parameters.get("category_id"); - if (categoryId == null) { - categoryId = request.getAttribute("productCategoryId"); - } +if (product) { + categoryId = parameters.category_id ?: request.getAttribute("productCategoryId"); // get the product price if (cart.isSalesOrder()) { // sales order: run the "calculateProductPrice" service - priceContext = UtilMisc.toMap("product", product, "currencyUomId", cart.getCurrency(), - "autoUserLogin", autoUserLogin, "userLogin", userLogin); - priceContext.put("webSiteId", webSiteId); - priceContext.put("prodCatalogId", catalogId); - priceContext.put("productStoreId", productStoreId); - priceContext.put("agreementId", cart.getAgreementId()); - priceContext.put("partyId", cart.getPartyId()); // IMPORTANT: otherwise it'll be calculating prices using the logged in user which could be a CSR instead of the customer - priceContext.put("checkIncludeVat", "Y"); + priceContext = [product : product, currencyUomId : cart.getCurrency(), + autoUserLogin : autoUserLogin, userLogin : userLogin]; + priceContext.webSiteId = webSiteId; + priceContext.prodCatalogId = catalogId; + priceContext.productStoreId = productStoreId; + priceContext.agreementId = cart.getAgreementId(); + priceContext.partyId = cart.getPartyId(); // IMPORTANT: otherwise it'll be calculating prices using the logged in user which could be a CSR instead of the customer + priceContext.checkIncludeVat = "Y"; priceMap = dispatcher.runSync("calculateProductPrice", priceContext); - context.put("price", priceMap); + context.price = priceMap; } else { // purchase order: run the "calculatePurchasePrice" service - priceContext = UtilMisc.toMap("product", product, "currencyUomId", cart.getCurrency(), - "partyId", cart.getPartyId(), "userLogin", userLogin); + priceContext = [product : product, currencyUomId : cart.getCurrency(), + partyId : cart.getPartyId(), userLogin : userLogin]; priceMap = dispatcher.runSync("calculatePurchasePrice", priceContext); - context.put("price", priceMap); + context.price = priceMap; } // get aggregated product totalPrice - if ("AGGREGATED".equals(product.getString("productTypeId"))) { + if ("AGGREGATED".equals(product.productTypeId)) { configWrapper = ProductConfigWorker.getProductConfigWrapper(productId, cart.getCurrency(), request); - if (configWrapper != null) { + if (configWrapper) { configWrapper.setDefaultConfig(); - context.put("totalPrice",configWrapper.getTotalPrice()); + context.totalPrice = configWrapper.getTotalPrice(); } } // get the product review(s) - reviews = product.getRelatedCache("ProductReview", null, UtilMisc.toList("-postedDateTime")); + reviews = product.getRelatedCache("ProductReview", null, ["-postedDateTime"]); } // get the average rating -if (reviews != null && reviews.size() > 0) { - reviewIter = reviews.iterator(); - double totalProductRating = 0; - long numRatings = 0; - while (reviewIter.hasNext()) { - productReview = reviewIter.next(); - productRating = productReview.get("productRating"); - if (productRating != null) { +if (reviews) { + totalProductRating = 0; + numRatings = 0; + reviews.each { productReview -> + productRating = productReview.productRating; + if (productRating) { totalProductRating += productRating; numRatings++; } } - if (numRatings > 0) { - context.put("averageRating", totalProductRating/numRatings); - context.put("numRatings", numRatings); + if (numRatings) { + context.averageRating = totalProductRating/numRatings; + context.numRatings = numRatings; } } // an example of getting features of a certain type to show -sizeProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "SIZE"), UtilMisc.toList("sequenceNum", "defaultSequenceNum")); +sizeProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", [productId : productId, productFeatureTypeId : "SIZE"], ["sequenceNum", "defaultSequenceNum"]); -context.put("product", product); -context.put("productStoreId", productStoreId); -context.put("categoryId", categoryId); -context.put("productReviews", reviews); -context.put("sizeProductFeatureAndAppls", sizeProductFeatureAndAppls); - +context.product = product; +context.productStoreId = productStoreId; +context.categoryId = categoryId; +context.productReviews = reviews; +context.sizeProductFeatureAndAppls = sizeProductFeatureAndAppls; Copied: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy (from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh) URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy?p2=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy&p1=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh&r1=675904&r2=676137&rev=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy Sat Jul 12 02:31:11 2008 @@ -29,26 +29,20 @@ import org.ofbiz.service.*; import org.ofbiz.product.catalog.*; -dispatcher = request.getAttribute("dispatcher"); currentCatalogId = CatalogWorker.getCurrentCatalogId(request); -categoryId = parameters.get("category_id"); -if (categoryId == null || categoryId.length() <= 0) - categoryId = CatalogWorker.getCatalogQuickaddCategoryPrimary(request); - -Collection quickAddCategories = CatalogWorker.getCatalogQuickaddCategories(request); -context.put("quickAddCats", quickAddCategories); -context.put("categoryId", categoryId); +categoryId = parameters.category_id ?: CatalogWorker.getCatalogQuickaddCategoryPrimary(request); -if (categoryId != null) { - fields = UtilMisc.toMap("productCategoryId", categoryId, "defaultViewSize", new Integer(10), - "limitView", new Boolean(false), "prodCatalogId", currentCatalogId, "checkViewAllow", Boolean.TRUE); +quickAddCategories = CatalogWorker.getCatalogQuickaddCategories(request); +context.quickAddCats = quickAddCategories; +context.categoryId = categoryId; + +if (categoryId) { + fields = [productCategoryId : categoryId, defaultViewSize : 10, + limitView : false, prodCatalogId : currentCatalogId, checkViewAllow : true]; result = dispatcher.runSync("getProductCategoryAndLimitedMembers", fields); - if (result != null) { - resultIter = result.keySet().iterator(); - while (resultIter.hasNext()) { - String name = (String) resultIter.next(); - context.put(name, result.get(name)); + if (result) { + result.each { key, value -> + context[key] = value; } } } - Copied: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy (from r675904, ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh) URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy?p2=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy&p1=ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh&r1=675904&r2=676137&rev=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy Sat Jul 12 02:31:11 2008 @@ -28,13 +28,13 @@ import javolution.util.FastMap; CategoryWorker.getRelatedCategories(request, "topLevelList", CatalogWorker.getCatalogTopCategoryId(request, CatalogWorker.getCurrentCatalogId(request)), true); -curCategoryId = UtilFormatOut.checkNull(parameters.get("category_id"), parameters.get("CATEGORY_ID")); +curCategoryId = parameters.category_id ?: parameters.CATEGORY_ID ?: ""; request.setAttribute("curCategoryId", curCategoryId); CategoryWorker.setTrail(request, curCategoryId); categoryList = request.getAttribute("topLevelList"); -if(categoryList != null) { +if(categoryList) { catContentWrappers = FastMap.newInstance(); CategoryWorker.getCategoryContentWrappers(catContentWrappers, categoryList, request); - context.put("catContentWrappers", catContentWrappers); + context.catContentWrappers = catContentWrappers; } Modified: ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml?rev=676137&r1=676136&r2=676137&view=diff ============================================================================== --- ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml (original) +++ ofbiz/trunk/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml Sat Jul 12 02:31:11 2008 @@ -45,7 +45,7 @@ <screen name="sidedeepcategory"> <section> <actions> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/SideDeepCategory.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://order/webapp/ordermgr/entry/catalog/sidedeepcategory.ftl"/></html></platform-specific> @@ -57,7 +57,7 @@ <section> <actions> <set field="showPriceDetails" value="Y"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://order/webapp/ordermgr/entry/catalog/productsummary.ftl"/></html></platform-specific> @@ -162,7 +162,7 @@ <set field="showPriceDetails" value="Y"/> <!--<script location="component://ecommerce/webapp/ecommerce/WEB-INF/actions/catalog/productdetail.bsh"/>--> <!-- Warning: this bsh file in the order component is slightly different from that of the ecommerce one (the currency is taken from the cart) --> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy"/> </actions> <widgets> <include-screen name="breadcrumbs"/> @@ -177,7 +177,7 @@ <section> <actions> <set field="productsummaryScreen" value="component://order/widget/ordermgr/OrderEntryCatalogScreens.xml#productsummary"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy"/> <!--<script location="component://ecommerce/webapp/ecommerce/WEB-INF/actions/catalog/prepareconfigform.bsh"/>--> <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/PrepareConfigForm.groovy"/> </actions> @@ -241,7 +241,7 @@ <set field="MainColumnStyle" value="center"/>--> <set field="title-property" value="PageTitleQuickAdd"/> <set field="quickaddsummaryScreen" value="component://order/widget/ordermgr/OrderEntryCatalogScreens.xml#quickaddsummary"/> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/quickadd.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/QuickAdd.groovy"/> </actions> <widgets> <decorator-screen name="CommonOrderCatalogDecorator" location="component://order/widget/ordermgr/OrderEntryCommonScreens.xml"> @@ -255,7 +255,7 @@ <screen name="quickaddsummary"> <section> <actions> - <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productsummary.bsh"/> + <script location="component://order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy"/> </actions> <widgets> <platform-specific><html><html-template location="component://order/webapp/ordermgr/entry/catalog/quickaddsummary.ftl"/></html></platform-specific> |
Free forum by Nabble | Edit this page |