This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch release17.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/release17.12 by this push: new f83be86 Fixed: display/selection of unit of measure is broken (OFBIZ-11955) f83be86 is described below commit f83be8652e86f8a3b5246bcc69dcb7004c172a3c Author: Jacques Le Roux <[hidden email]> AuthorDate: Sun Aug 30 14:08:35 2020 +0200 Fixed: display/selection of unit of measure is broken (OFBIZ-11955) This fixes in in order component Thanks: Alex Conflict handled by hand in ProductSummary.ftl --- .../entry/catalog/InlineProductDetail.groovy | 7 +++ .../entry/catalog/ProductDetail.groovy | 11 +++++ .../entry/catalog/ProductSummary.groovy | 7 +++ .../order/template/entry/catalog/ProductDetail.ftl | 14 ++++++ .../template/entry/catalog/ProductSummary.ftl | 14 +++--- .../template/entry/catalog/ProductVariantJS.ftl | 51 ++++++++++++++++++++++ .../widget/ordermgr/OrderEntryCatalogScreens.xml | 8 ++++ 7 files changed, 107 insertions(+), 5 deletions(-) diff --git a/applications/order/groovyScripts/entry/catalog/InlineProductDetail.groovy b/applications/order/groovyScripts/entry/catalog/InlineProductDetail.groovy index 1d3ac61..5d4c7f6 100644 --- a/applications/order/groovyScripts/entry/catalog/InlineProductDetail.groovy +++ b/applications/order/groovyScripts/entry/catalog/InlineProductDetail.groovy @@ -102,6 +102,9 @@ if (inlineProduct) { featureTypes = [:] featureOrder = [] + variantInfoJS = new StringBuffer() + variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n \$(document).ready(function(\$) {\n") + // make the productContentWrapper productContentWrapper = new ProductContentWrapper(inlineProduct, request) context.productContentWrapper = productContentWrapper @@ -284,7 +287,9 @@ if (inlineProduct) { variantPriceMap = runService('calculateProductPrice', priceContext) } amt.append(" if (sku == \"" + variant.productId + "\") return \"" + (variant.requireAmount ?: "N") + "\"; ") + variantInfoJS.append(" variantReqAmounts['" + variant.productId + "'] = '" + (variant.requireAmount ?: "N") + "';\n") variantPriceJS.append(" if (sku == \"" + variant.productId + "\") return \"" + numberFormat.format(variantPriceMap.basePrice) + "\"; ") + variantInfoJS.append(" variantPrices['" + variant.productId + "'] = '" + numberFormat.format(variantPriceMap.basePrice) + "';\n") } amt.append(" } ") variantPriceJS.append(" } ") @@ -298,4 +303,6 @@ if (inlineProduct) { } } } + variantInfoJS.append(" });\n</script>\n") + context.variantInfoJavaScript = variantInfoJS } diff --git a/applications/order/groovyScripts/entry/catalog/ProductDetail.groovy b/applications/order/groovyScripts/entry/catalog/ProductDetail.groovy index aa7fd2d..ff568ce 100644 --- a/applications/order/groovyScripts/entry/catalog/ProductDetail.groovy +++ b/applications/order/groovyScripts/entry/catalog/ProductDetail.groovy @@ -106,6 +106,9 @@ if (product) { featureTypes = [:] featureOrder = [] + variantInfoJS = new StringBuffer() + variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n \$(document).ready(function(\$) {\n") + // set this as a last viewed LAST_VIEWED_TO_KEEP = 10 // modify this to change the number of last viewed to keep lastViewedProducts = session.getAttribute("lastViewedProducts") @@ -440,8 +443,10 @@ if (product) { variantPriceMap = runService('calculatePurchasePrice', priceContext) } amt.append(" if (sku == \"" + variant.productId + "\") return \"" + (variant.requireAmount ?: "N") + "\"; ") + variantInfoJS.append(" variantReqAmounts['" + variant.productId + "'] = '" + (variant.requireAmount ?: "N") + "';\n") if (variantPriceMap && variantPriceMap.basePrice) { variantPriceJS.append(" if (sku == \"" + variant.productId + "\") return \"" + UtilFormatOut.formatCurrency(variantPriceMap.basePrice, currencyUomId, locale, 10) + "\"; ") + variantInfoJS.append(" variantPrices['" + variant.productId + "'] = '" + UtilFormatOut.formatCurrency(variantPriceMap.basePrice, currencyUomId, locale, 10) + "';\n") } // make a list of virtual variants sku with requireAmount @@ -481,9 +486,11 @@ if (product) { } variantPriceList.add(virtualPriceMap) variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + UtilFormatOut.formatCurrency(variantPriceMap.basePrice, currencyUomId, locale, 10) + "\"; ") + variantInfoJS.append(" variantPrices['" + virtual.productId + "'] = '" + UtilFormatOut.formatCurrency(variantPriceMap.basePrice, currencyUomId, locale, 10) + "';\n") } else { virtualPriceMap = runService('calculatePurchasePrice', priceContext) variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + UtilFormatOut.formatCurrency(variantPriceMap.price, currencyUomId, locale, 10) + "\"; ") + variantInfoJS.append(" variantPrices['" + virtual.productId + "'] = '" + UtilFormatOut.formatCurrency(variantPriceMap.price, currencyUomId, locale, 10) + "';\n") } } @@ -537,9 +544,11 @@ if (product) { // Get the minimum quantity for variants if MINIMUM_ORDER_PRICE is set for variants. virtualVariantPriceList.add(virtualPriceMap) variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + UtilFormatOut.formatCurrency(virtualPriceMap.basePrice, currencyUomId, locale, 10) + "\"; ") + variantInfoJS.append(" variantPrices['" + virtual.productId + "'] = '" + UtilFormatOut.formatCurrency(virtualPriceMap.basePrice, currencyUomId, locale, 10) + "';\n") } else { virtualPriceMap = runService('calculatePurchasePrice', priceContext) variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + UtilFormatOut.formatCurrency(virtualPriceMap.price, currencyUomId, locale, 10) + "\"; ") + variantInfoJS.append(" variantPrices['" + virtual.productId + "'] = '" + UtilFormatOut.formatCurrency(virtualPriceMap.price, currencyUomId, locale, 10) + "';\n") } } variantPriceJS.append(" } ") @@ -552,6 +561,8 @@ if (product) { } } } + variantInfoJS.append(" });\n</script>\n") + context.variantInfoJavaScript = variantInfoJS availableInventory = 0.0 diff --git a/applications/order/groovyScripts/entry/catalog/ProductSummary.groovy b/applications/order/groovyScripts/entry/catalog/ProductSummary.groovy index 2137ac4..6e5c7a7 100644 --- a/applications/order/groovyScripts/entry/catalog/ProductSummary.groovy +++ b/applications/order/groovyScripts/entry/catalog/ProductSummary.groovy @@ -99,6 +99,9 @@ reviews = null if (product) { categoryId = parameters.category_id ?: request.getAttribute("productCategoryId") + variantInfoJS = new StringBuffer() + variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n jQuery(document).ready(function(jQuery) {\n") + // get the product price if (cart.isSalesOrder()) { // sales order: run the "calculateProductPrice" service @@ -194,6 +197,7 @@ if (product) { basePrice = UtilProperties.getResourceBundleMap("CommonUiLabels", locale).get("CommonNA") } variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + basePrice + "\"; ") + variantInfoJS.append(" variantPrices['" + virtual.productId + "'] = '" + basePrice + "';\n") } variantPriceJS.append(" } ") @@ -204,6 +208,9 @@ if (product) { context.virtualJavaScript = jsBuf } } + variantInfoJS.append(" });\n</script>\n") + context.variantInfoJavaScript = variantInfoJS + context.mainProducts = mainProducts } diff --git a/applications/order/template/entry/catalog/ProductDetail.ftl b/applications/order/template/entry/catalog/ProductDetail.ftl index e44832e..af4b77d 100644 --- a/applications/order/template/entry/catalog/ProductDetail.ftl +++ b/applications/order/template/entry/catalog/ProductDetail.ftl @@ -281,6 +281,8 @@ ${virtualJavaScript!} //--> </script> +${screens.render("component://order/widget/ordermgr/OrderEntryCatalogScreens.xml#productvariantjs")} +${variantInfoJavaScript!} <div id="productdetail"> <table border="0" cellpadding="2" cellspacing="0" width="100%"> @@ -498,6 +500,18 @@ ${virtualJavaScript!} <#else> <input type="hidden" name="product_id" value="${product.productId}"/> <input type="hidden" name="add_product_id" value="${product.productId}"/> + <#if mainProducts?has_content> + <select name="productVariantId" class="form-control" onchange="javascript:variantUomSelection(this);"> + <option value="">${uiLabelMap.CommonSelect} ${uiLabelMap.ProductUnitOfMeasure}</option> + <#list mainProducts as mainProduct> + <option value="${mainProduct.productId}">${mainProduct.uomDesc} : ${mainProduct.piecesIncluded}</option> + </#list> + </select><br/> + <div class="variant-price" style="display: none;"> + <strong><span class="product_id_display"> </span></strong> + <strong><span class="variant_price_display"> </span></strong> + </div> + </#if> <#if productStoreId??> <#assign isStoreInventoryNotAvailable = !(Static["org.apache.ofbiz.product.store.ProductStoreWorker"].isStoreInventoryAvailable(request, product, 1.0?double))> <#assign isStoreInventoryRequired = Static["org.apache.ofbiz.product.store.ProductStoreWorker"].isStoreInventoryRequired(request, product)> diff --git a/applications/order/template/entry/catalog/ProductSummary.ftl b/applications/order/template/entry/catalog/ProductSummary.ftl index 553bf83..bee8131 100644 --- a/applications/order/template/entry/catalog/ProductSummary.ftl +++ b/applications/order/template/entry/catalog/ProductSummary.ftl @@ -51,6 +51,8 @@ ${virtualJavaScript!} } //--> </script> +${screens.render("component://order/widget/ordermgr/OrderEntryCatalogScreens.xml#productvariantjs")} +${variantInfoJavaScript!} <#if product??> <#-- variable setup --> <#if "Y" == backendPath?default("N")> @@ -94,6 +96,7 @@ ${virtualJavaScript!} </table> </div> <script type="text/javascript"> + jQuery(document).ready(function(jQuery) { jQuery("#${productInfoLinkId}").attr('title', jQuery("#${productDetailId}").remove().html()); jQuery("#${productInfoLinkId}").tooltip({ content: function(){ @@ -102,6 +105,7 @@ ${virtualJavaScript!} tooltipClass: "popup", track: true }); + }); </script> <div class="productbuy"> <#-- check to see if introductionDate hasn't passed yet --> @@ -133,15 +137,15 @@ ${virtualJavaScript!} <a href="javascript:document.the${requestAttributes.formNamePrefix!}${requestAttributes.listIndex!}form.submit()" class="buttontext">${uiLabelMap.OrderAddToCart}</a> <#if mainProducts?has_content> <input type="hidden" name="product_id" value=""/> - <select name="productVariantId" onchange="javascript:displayProductVirtualId(this.value, '${product.productId}', this.form);"> - <option value="">Select Unit Of Measure</option> + <select name="productVariantId" onchange="javascript:variantUomSelection(this);" style="width: 100%;"> + <option value="">${uiLabelMap.CommonSelect} ${uiLabelMap.ProductUnitOfMeasure}</option> <#list mainProducts as mainProduct> <option value="${mainProduct.productId}">${mainProduct.uomDesc} : ${mainProduct.piecesIncluded}</option> </#list> </select> - <div style="display: inline-block;"> - <strong><span id="product_id_display"> </span></strong> - <strong><span id="variant_price_display"> </span></strong> + <div class="variant-price" style="display: none;"> + <strong><span class="product_id_display"> </span></strong> + <strong><span class="variant_price_display"> </span></strong> </div> </#if> </form> diff --git a/applications/order/template/entry/catalog/ProductVariantJS.ftl b/applications/order/template/entry/catalog/ProductVariantJS.ftl new file mode 100644 index 0000000..0912299 --- /dev/null +++ b/applications/order/template/entry/catalog/ProductVariantJS.ftl @@ -0,0 +1,51 @@ +<#-- +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. +--> +<script language="JavaScript" type="text/javascript"> +if (typeof(checkAmtReq2) == 'undefined') { + + var variantReqAmounts = {}; + function checkAmtReq2(sku) { + return variantReqAmounts[sku]; + } + + var variantPrices = {}; + function getVariantPrice2(sku) { + return variantPrices[sku]; + } + + function variantUomSelection (select) { + var $select = $(select); + var form = $select.closest('form'); + var price_div = $('.variant-price', form); + var variantId = $select.val() || ''; + $("[name='product_id']", form).val(variantId); + $('.product_id_display', price_div).text(variantId); + + var price = getVariantPrice2(variantId); + if (price) { + $('.variant_price_display', price_div).text(price); + price_div.css('display', 'inline-block'); + } + else { + price_div.hide(); + } + } + +} +</script> diff --git a/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml b/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml index de199e6..033bf27 100644 --- a/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml +++ b/applications/order/widget/ordermgr/OrderEntryCatalogScreens.xml @@ -66,6 +66,14 @@ under the License. </section> </screen> + <screen name="productvariantjs"> + <section> + <widgets> + <platform-specific><html><html-template location="component://order/template/entry/catalog/ProductVariantJS.ftl"/></html></platform-specific> + </widgets> + </section> + </screen> + <screen name="breadcrumbs"> <section> <actions> |
Free forum by Nabble | Edit this page |