/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.lang.* import java.util.* import java.text.NumberFormat import org.apache.ofbiz.base.util.* import org.apache.ofbiz.service.* import org.apache.ofbiz.entity.* import org.apache.ofbiz.entity.condition.* import org.apache.ofbiz.entity.util.* import org.apache.ofbiz.webapp.taglib.ContentUrlTag import org.apache.ofbiz.webapp.stats.VisitHandler import org.apache.ofbiz.webapp.website.WebSiteWorker import org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents import org.apache.ofbiz.product.catalog.* import org.apache.ofbiz.product.category.* import org.apache.ofbiz.product.product.ProductWorker import org.apache.ofbiz.product.product.ProductContentWrapper import org.apache.ofbiz.product.product.ProductSearch import org.apache.ofbiz.product.product.ProductSearchSession import org.apache.ofbiz.product.store.* inlineProductId = request.getAttribute("inlineProductId") inlineCounter = request.getAttribute("inlineCounter") context.inlineCounter = inlineCounter context.inlineProductId = inlineProductId contentPathPrefix = CatalogWorker.getContentPathPrefix(request) catalogName = CatalogWorker.getCatalogName(request) currentCatalogId = CatalogWorker.getCurrentCatalogId(request) if (inlineProductId) { inlineProduct = from("Product").where("productId", inlineProductId).cache(true).queryOne() if (inlineProduct) { context.product = inlineProduct contentWrapper = new ProductContentWrapper(inlineProduct, request) context.put("title", contentWrapper.get("PRODUCT_NAME", "html")) context.put("metaDescription", contentWrapper.get("DESCRIPTION", "html")) productTemplate = product.detailScreen if (productTemplate) { detailScreen = productTemplate } } } templatePathPrefix = CatalogWorker.getTemplatePathPrefix(request) if (templatePathPrefix) { detailScreen = templatePathPrefix + detailScreen } context.detailScreen = detailScreen String buildNext(Map map, List order, String current, String prefix, Map featureTypes) { def ct = 0 def buf = new StringBuffer() buf.append("function listFT" + inlineCounter + current + prefix + "() { ") buf.append("document.forms[\"configform\"].elements[\"FT" + inlineCounter + current + "\"].options.length = 1;") buf.append("document.forms[\"configform\"].elements[\"FT" + inlineCounter + current + "\"].options[0] = new Option(\"" + featureTypes[current] + "\",\"\",true,true);") map.each { key, value -> def optValue = null if (order.indexOf(current) == (order.size()-1)) { optValue = value.iterator().next() } else { optValue = prefix + "_" + ct } buf.append("document.forms[\"configform\"].elements[\"FT" + inlineCounter + current + "\"].options[" + (ct + 1) + "] = new Option(\"" + key + "\",\"" + optValue + "\");") ct++ } buf.append(" }") if (order.indexOf(current) < (order.size()-1)) { ct = 0 map.each { key, value -> def nextOrder = order.get(order.indexOf(current)+1) def newPrefix = prefix + "_" + ct buf.append(buildNext(value, order, nextOrder, newPrefix, featureTypes)) ct++ } } return buf.toString() } cart = ShoppingCartEvents.getCartObject(request) // set the content path prefix contentPathPrefix = CatalogWorker.getContentPathPrefix(request) context.contentPathPrefix = contentPathPrefix // get the product detail information if (inlineProduct) { inlineProductId = inlineProduct.productId productTypeId = inlineProduct.productTypeId featureTypes = [:] featureOrder = [] // make the productContentWrapper productContentWrapper = new ProductContentWrapper(inlineProduct, request) context.productContentWrapper = productContentWrapper // get the main detail image (virtual or single product) mainDetailImage = productContentWrapper.get("DETAIL_IMAGE_URL", "url") if (mainDetailImage) { mainDetailImageUrl = ContentUrlTag.getContentPrefix(request) + mainDetailImage context.mainDetailImageUrl = mainDetailImageUrl.toString() } // get the product price webSiteId = WebSiteWorker.getWebSiteId(request) autoUserLogin = request.getSession().getAttribute("autoUserLogin") if (cart.isSalesOrder()) { // sales order: run the "calculateProductPrice" service priceContext = [product : inlineProduct, prodCatalogId : currentCatalogId, 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 = runService('calculateProductPrice', priceContext) context.priceMap = priceMap } else { // purchase order: run the "calculatePurchasePrice" service priceContext = [product : inlineProduct, currencyUomId : cart.getCurrency(), partyId : cart.getPartyId(), userLogin : userLogin] priceMap = runService('calculatePurchasePrice', priceContext) context.priceMap = priceMap } context.variantTree = null context.variantTreeSize = null context.variantSample = null context.variantSampleKeys = null context.variantSampleSize = null if ("Y".equals(inlineProduct.isVirtual)) { if ("VV_FEATURETREE".equals(ProductWorker.getProductVirtualVariantMethod(delegator, inlineProductId))) { context.featureLists = ProductWorker.getSelectableProductFeaturesByTypesAndSeq(inlineProduct) } else { featureMap = runService("getProductFeatureSet", [productId : inlineProductId]) featureSet = featureMap.featureSet if (featureSet) { variantTreeMap = runService('getProductVariantTree', [productId : inlineProductId, 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) { featureOrder = new LinkedList(featureSet) featureOrder.each { featureKey -> featureValue = from("ProductFeatureType").where("productFeatureTypeId", featureKey).cache(true).queryOne() fValue = featureValue.get("description") ?: featureValue.productFeatureTypeId featureTypes[featureKey] = fValue } } context.featureTypes = featureTypes context.featureOrder = featureOrder if (featureOrder) { context.featureOrderFirst = featureOrder[0] } if (variantTree && imageMap) { jsBuf = new StringBuffer() jsBuf.append("") context.virtualJavaScript = jsBuf } } } } }