Fixed: display/selection of unit of measure is broken (OFBIZ-11955)

Improve code for UOM dropdown of products like WG-9943

Thanks: Alex
This commit is contained in:
Jacques Le Roux
2020-09-11 10:43:13 +02:00
parent 93eb9c65a2
commit d04f777389
6 changed files with 72 additions and 81 deletions
@@ -103,7 +103,7 @@ if (inlineProduct) {
featureOrder = []
variantInfoJS = new StringBuffer()
variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n \$(document).ready(function(\$) {\n")
variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n jQuery(document).ready(function(jQuery) {\n")
// make the productContentWrapper
productContentWrapper = new ProductContentWrapper(inlineProduct, request)
@@ -107,7 +107,7 @@ if (product) {
featureOrder = []
variantInfoJS = new StringBuffer()
variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n \$(document).ready(function(\$) {\n")
variantInfoJS.append("<script language=\"JavaScript\" type=\"text/javascript\">\n jQuery(document).ready(function(jQuery) {\n")
// set this as a last viewed
LAST_VIEWED_TO_KEEP = 10 // modify this to change the number of last viewed to keep
@@ -561,6 +561,7 @@ if (product) {
}
}
}
variantInfoJS.append(" variantPrices['" + product.productId + "'] = '" + UtilFormatOut.formatCurrency(priceMap.basePrice, currencyUomId, locale, 10) + "';\n")
variantInfoJS.append(" });\n</script>\n")
context.variantInfoJavaScript = variantInfoJS
@@ -97,6 +97,7 @@ if (product) {
categoryId = null
reviews = null
if (product) {
numberFormat = NumberFormat.getCurrencyInstance(locale)
categoryId = parameters.category_id ?: request.getAttribute("productCategoryId")
variantInfoJS = new StringBuffer()
@@ -170,7 +171,6 @@ if (product) {
}
}
variantPriceList = []
numberFormat = NumberFormat.getCurrencyInstance(locale)
if(virtualVariants){
amt = new StringBuffer()
@@ -208,6 +208,7 @@ if (product) {
context.virtualJavaScript = jsBuf
}
}
variantInfoJS.append(" variantPrices['" + product.productId + "'] = '" + numberFormat.format(priceMap.basePrice) + "';\n")
variantInfoJS.append(" });\n</script>\n")
context.variantInfoJavaScript = variantInfoJS
@@ -17,56 +17,30 @@ specific language governing permissions and limitations
under the License.
-->
<#-- variable setup -->
<#assign price = priceMap!/>
<#assign price = priceMap! />
<#-- end variable setup -->
<#-- virtual product javascript -->
${virtualJavaScript!}
${virtualVariantJavaScript!}
<script type="application/javascript">
var detailImageUrl = null;
function setAddProductId(name) {
document.addform.add_product_id.value = name;
if (document.addform.quantity == null) return;
if (name == '' || name == 'NULL' || isVirtual(name) == true) {
document.addform.quantity.disabled = true;
var elem = document.getElementById('product_id_display');
var txt = document.createTextNode('');
if(elem.hasChildNodes()) {
elem.replaceChild(txt, elem.firstChild);
} else {
elem.appendChild(txt);
}
} else {
document.addform.quantity.disabled = false;
var elem = document.getElementById('product_id_display');
var txt = document.createTextNode(name);
if(elem.hasChildNodes()) {
elem.replaceChild(txt, elem.firstChild);
} else {
elem.appendChild(txt);
}
function setAddProductId2(sku, with_bak) {
document.addform.add_product_id.value = sku;
var disable = (sku == '' || sku == 'NULL' || isVirtual(sku) == true);
if (document.addform.quantity != null) {
document.addform.quantity.disabled = disable;
}
var txt = disable ? '' : sku;
$('#product_id_display').text(txt);
if (with_bak) {
document.addform.product_id_bak.value = txt;
}
}
function setVariantPrice(sku) {
if (sku == '' || sku == 'NULL' || isVirtual(sku) == true) {
var elem = document.getElementById('variant_price_display');
var txt = document.createTextNode('');
if(elem.hasChildNodes()) {
elem.replaceChild(txt, elem.firstChild);
} else {
elem.appendChild(txt);
}
}
else {
var elem = document.getElementById('variant_price_display');
var price = getVariantPrice(sku);
var txt = document.createTextNode(price);
if(elem.hasChildNodes()) {
elem.replaceChild(txt, elem.firstChild);
} else {
elem.appendChild(txt);
}
}
function setVariantPrice2(sku) {
var disable = (sku == '' || sku == 'NULL' || isVirtual(sku) == true);
var txt = disable ? '' : getVariantPrice2(sku);
$('#variant_price_display').text(txt || '');
}
function isVirtual(product) {
var isVirtual = false;
@@ -158,11 +132,15 @@ ${virtualJavaScript!}
} else {
var Variable1 = eval("list" + OPT[(currentFeatureIndex+1)] + selectedValue + "()");
}
// reset uom select
$('#product_uom').text('');
// set the product ID to NULL to trigger the alerts
setAddProductId('NULL');
setAddProductId2('NULL');
// set the variant price to NULL
setVariantPrice('NULL');
setVariantPrice2('NULL');
} else {
// this is the final selection -- locate the selected index of the last selection
var indexSelected = document.forms["addform"].elements[name].selectedIndex;
@@ -174,13 +152,13 @@ ${virtualJavaScript!}
ajaxUpdateArea("product_uom", "<@ofbizUrl>ProductUomDropDownOnly</@ofbizUrl>", "productId=" + sku);
// set the product ID
setAddProductId(sku);
setAddProductId2(sku, true);
// set the variant price
setVariantPrice(sku);
setVariantPrice2(sku);
// check for amount box
toggleAmt(checkAmtReq(sku));
toggleAmt(checkAmtReq2(sku));
}
}
@@ -207,7 +185,7 @@ ${virtualJavaScript!}
}
function showAlert(msg) {
showErrorAlert("${uiLabelMap.CommonErrorMessage2}",msg);
showErrorAlert("${uiLabelMap.CommonErrorMessage2}", msg);
}
function additemSubmit(){
@@ -265,18 +243,6 @@ ${virtualJavaScript!}
block2.style.display = "none";
}
</#if>
function displayProductVirtualVariantId(variantId) {
document.addform.product_id.value = variantId;
var elem = document.getElementById('product_id_display');
var txt = document.createTextNode(variantId);
if(elem.hasChildNodes()) {
elem.replaceChild(txt, elem.firstChild);
} else {
elem.appendChild(txt);
}
setVariantPrice(variantId);
}
</script>
${screens.render("component://order/widget/ordermgr/OrderEntryCatalogScreens.xml#productvariantjs")}
@@ -321,9 +287,9 @@ ${variantInfoJavaScript!}
<#if sizeProductFeatureAndAppls?has_content>
<div>
<#if (sizeProductFeatureAndAppls?size == 1)>
Size:
${uiLabelMap.OrderSizeAvailableSingle}:
<#else>
Sizes Available:
${uiLabelMap.OrderSizeAvailableMultiple}:
</#if>
<#list sizeProductFeatureAndAppls as sizeProductFeatureAndAppl>
${sizeProductFeatureAndAppl.description?default(sizeProductFeatureAndAppl.abbrev?default(sizeProductFeatureAndAppl.productFeatureId))}<#if sizeProductFeatureAndAppl_has_next>,</#if>
@@ -482,9 +448,10 @@ ${variantInfoJavaScript!}
</div>
</#list>
<span id="product_uom"></span><br/>
<div class="variant-price" style="display: none;">
<strong><span class="product_id_display"> </span></strong>
<strong><span class="variant_price_display"> </span></strong>
<input type="hidden" name="product_id_bak" value=""/>
<div class="variant-price" style="display: inline-block;">
<strong><span id="product_id_display" class="product_id_display"> </span></strong>
<strong><span id="variant_price_display" class="variant_price_display"> </span></strong>
</div>
<input type="hidden" name="product_id" value="${product.productId}"/>
<input type="hidden" name="add_product_id" value="NULL"/>
@@ -505,7 +472,8 @@ ${variantInfoJavaScript!}
<option value="${mainProduct.productId}">${mainProduct.uomDesc} : ${mainProduct.piecesIncluded}</option>
</#list>
</select><br/>
<div class="variant-price" style="display: none;">
<input type="hidden" name="product_id_bak" value="${product.productId}"/>
<div class="variant-price" style="display: inline-block;">
<strong><span class="product_id_display"> </span></strong>
<strong><span class="variant_price_display"> </span></strong>
</div>
@@ -552,7 +520,7 @@ ${variantInfoJavaScript!}
<td nowrap="nowrap" align="right">Number of persons</td>
<td><input type="text" size="4" name="reservPersons" value="2"/></td>
</#if>
<td nowrap="nowrap" align="right">Quantity</td>
<td nowrap="nowrap" align="right">${uiLabelMap.CommonQuantity}</td>
<td><input type="text" size="5" name="quantity" value="1"/></td>
</tr>
</table>
@@ -94,6 +94,7 @@ ${variantInfoJavaScript!}
</table>
</div>
<script type="application/javascript">
/*
jQuery(document).ready(function(jQuery) {
jQuery("#${productInfoLinkId}").attr('title', jQuery("#${productDetailId}").remove().html());
jQuery("#${productInfoLinkId}").tooltip({
@@ -104,6 +105,7 @@ ${variantInfoJavaScript!}
track: true
});
});
*/
</script>
<div class="productbuy">
<#-- check to see if introductionDate hasn't passed yet -->
@@ -141,7 +143,8 @@ ${variantInfoJavaScript!}
<option value="${mainProduct.productId}">${mainProduct.uomDesc} : ${mainProduct.piecesIncluded}</option>
</#list>
</select>
<div class="variant-price" style="display: none;">
<input type="hidden" name="product_id_bak" value="${product.productId}"/>
<div class="variant-price" style="display: inline-block;">
<strong><span class="product_id_display"> </span></strong>
<strong><span class="variant_price_display"> </span></strong>
</div>
@@ -32,20 +32,38 @@ if (typeof(checkAmtReq2) == 'undefined') {
function variantUomSelection (select) {
var $select = $(select);
var form = $select.closest('form');
var price_div = $('.variant-price', form);
var variantId = $select.val() || '';
var variantId = $select.val();
$("[name='product_id']", form).val(variantId);
$('.product_id_display', price_div).text(variantId);
if (!variantId) {
variantId = $("[name='product_id_bak']", form).val() || '';
}
$('.product_id_display', form).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();
}
$('.variant_price_display', form).text(price || '');
// var price_div = $('.variant-price', form);
// if (price) {
// price_div.css('display', 'inline-block');
// }
// else {
// price_div.hide();
// }
}
jQuery(document).ready(function(jQuery) {
jQuery('.popup_link').each(
function(index) {
var $this = jQuery(this);
var popup = $('.popup', $this.closest('.productsummary'));
$this.attr('title', popup.remove().html());
$this.tooltip({
content: function(){
return this.getAttribute("title");
},
tooltipClass: "popup",
track: true
});
});
});
}
</script>