Author: hansbak
Date: Fri Dec 24 06:53:27 2010 New Revision: 1052458 URL: http://svn.apache.org/viewvc?rev=1052458&view=rev Log: also add alternative packaging on non variant products and include demo data for that Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productsummary.ftl ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Fri Dec 24 06:53:27 2010 @@ -381,6 +381,7 @@ public class ShoppingCartHelper { String productId = null; String quantStr = null; String itemGroupNumberToUse = itemGroupNumber; + String originalProductId = null; if (entry.getKey() instanceof String) { String key = (String) entry.getKey(); //Debug.logInfo("Bulk Key: " + key, module); @@ -413,9 +414,26 @@ public class ShoppingCartHelper { quantity = BigDecimal.ZERO; } if (quantity.compareTo(BigDecimal.ZERO) > 0) { + // check for alternative packing + if(ProductWorker.isAlternativePacking(delegator, null , productId)){ + GenericValue originalProduct = null; + originalProductId = productId; + productId = ProductWorker.getOriginalProductId(delegator, productId); + try { + originalProduct = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", originalProductId)); + } catch (GenericEntityException e) { + Debug.logError(e, "Error getting parent product", module); + } + BigDecimal piecesIncluded = BigDecimal.ZERO; + if(originalProduct != null){ + piecesIncluded = new BigDecimal(originalProduct.getLong("piecesIncluded")); + quantity = quantity.multiply(piecesIncluded); + } + } + try { if (Debug.verboseOn()) Debug.logVerbose("Bulk Adding to cart [" + quantity + "] of [" + productId + "] in Item Group [" + itemGroupNumber + "]", module); - this.cart.addOrIncreaseItem(productId, null, quantity, null, null, null, null, null, null, null, catalogId, null, null, itemGroupNumberToUse, null, dispatcher); + this.cart.addOrIncreaseItem(productId, null, quantity, null, null, null, null, null, null, null, catalogId, null, null, itemGroupNumberToUse, originalProductId, dispatcher); } catch (CartItemModifyException e) { return ServiceUtil.returnError(e.getMessage()); } catch (ItemNotFoundException e) { Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java Fri Dec 24 06:53:27 2010 @@ -1116,7 +1116,7 @@ public class ShoppingCartItem implements // check alternative packaging boolean isAlternativePacking = ProductWorker.isAlternativePacking(delegator, this.productId , this.getParentProductId()); BigDecimal pieces = BigDecimal.ONE; - if(isAlternativePacking){ + if(isAlternativePacking && UtilValidate.isNotEmpty(this.getParentProduct())){ GenericValue originalProduct = this.getParentProduct(); if (originalProduct != null) pieces = new BigDecimal(originalProduct.getLong("piecesIncluded")); priceContext.put("product", originalProduct); Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy Fri Dec 24 06:53:27 2010 @@ -233,7 +233,27 @@ if (product) { // an example of getting features of a certain type to show sizeProductFeatureAndAppls = delegator.findByAnd("ProductFeatureAndAppl", [productId : productId, productFeatureTypeId : "SIZE"], ["sequenceNum", "defaultSequenceNum"]); context.sizeProductFeatureAndAppls = sizeProductFeatureAndAppls; - + + // get product variant for Box/Case/Each + productVariants = []; + boolean isAlternativePacking = ProductWorker.isAlternativePacking(delegator, product.productId, null); + mainProducts = []; + if(isAlternativePacking){ + productVirtualVariants = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productIdTo", product.productId , "productAssocTypeId", "ALTERNATIVE_PACKAGE")); + if(productVirtualVariants){ + productVirtualVariants.each { virtualVariantKey -> + mainProductMap = [:]; + mainProduct = virtualVariantKey.getRelatedOneCache("MainProduct"); + quantityUom = mainProduct.getRelatedOneCache("QuantityUom"); + mainProductMap.productId = mainProduct.productId; + mainProductMap.piecesIncluded = mainProduct.piecesIncluded; + mainProductMap.uomDesc = quantityUom.description; + mainProducts.add(mainProductMap); + } + } + } + context.mainProducts = mainProducts; + // Special Variant Code if ("Y".equals(product.isVirtual)) { if ("VV_FEATURETREE".equals(ProductWorker.getProductVirtualVariantMethod(delegator, productId))) { @@ -476,7 +496,55 @@ if (product) { } } else { context.minimumQuantity= ShoppingCart.getMinimumOrderQuantity(delegator, priceMap.price, productId); - } + if(isAlternativePacking){ + // get alternative product price when product doesn't have any feature + jsBuf = new StringBuffer(); + jsBuf.append("<script language=\"JavaScript\" type=\"text/javascript\">"); + + // make a list of variant sku with requireAmount + virtualVariantsRes = dispatcher.runSync("getAssociatedProducts", [productIdTo : productId, type : "ALTERNATIVE_PACKAGE", checkViewAllow : true, prodCatalogId : categoryId]); + virtualVariants = virtualVariantsRes.assocProducts; + // Format to apply the currency code to the variant price in the javascript + if (productStore) { + localeString = productStore.defaultLocaleString; + if (localeString) { + locale = UtilMisc.parseLocale(localeString); + } + } + virtualVariantPriceList = []; + numberFormat = NumberFormat.getCurrencyInstance(locale); + + if(virtualVariants){ + amt = new StringBuffer(); + // Create the javascript to return the price for each variant + variantPriceJS = new StringBuffer(); + variantPriceJS.append("function getVariantPrice(sku) { "); + + virtualVariants.each { virtualAssoc -> + virtual = virtualAssoc.getRelatedOne("MainProduct"); + // Get price from a virtual product + priceContext.product = virtual; + if (cart.isSalesOrder()) { + // sales order: run the "calculateProductPrice" service + virtualPriceMap = dispatcher.runSync("calculateProductPrice", priceContext); + BigDecimal calculatedPrice = (BigDecimal)virtualPriceMap.get("price"); + // Get the minimum quantity for variants if MINIMUM_ORDER_PRICE is set for variants. + virtualVariantPriceList.add(virtualPriceMap); + } else { + virtualPriceMap = dispatcher.runSync("calculatePurchasePrice", priceContext); + } + variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + numberFormat.format(virtualPriceMap.basePrice) + "\"; "); + } + variantPriceJS.append(" } "); + + context.virtualVariantPriceList = virtualVariantPriceList; + jsBuf.append(amt.toString()); + jsBuf.append(variantPriceJS.toString()); + jsBuf.append("</script>"); + context.virtualVariantJavaScript = jsBuf; + } + } + } //get last inventory count from product facility for the product facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition([productId : product.productId]), null, null, null, false); Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductSummary.groovy Fri Dec 24 06:53:27 2010 @@ -31,7 +31,8 @@ import org.ofbiz.product.config.ProductC import org.ofbiz.product.catalog.*; import org.ofbiz.product.store.*; import org.ofbiz.order.shoppingcart.*; - +import org.ofbiz.product.product.ProductWorker; +import java.text.NumberFormat; //either optProduct, optProductId or productId must be specified product = request.getAttribute("optProduct"); @@ -126,6 +127,73 @@ if (product) { // get the product review(s) reviews = product.getRelatedCache("ProductReview", null, ["-postedDateTime"]); + + // get product variant for Box/Case/Each + productVariants = []; + boolean isAlternativePacking = ProductWorker.isAlternativePacking(delegator, product.productId, null); + mainProducts = []; + if(isAlternativePacking){ + productVirtualVariants = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productIdTo", product.productId , "productAssocTypeId", "ALTERNATIVE_PACKAGE")); + if(productVirtualVariants){ + productVirtualVariants.each { virtualVariantKey -> + mainProductMap = [:]; + mainProduct = virtualVariantKey.getRelatedOneCache("MainProduct"); + quantityUom = mainProduct.getRelatedOneCache("QuantityUom"); + mainProductMap.productId = mainProduct.productId; + mainProductMap.piecesIncluded = mainProduct.piecesIncluded; + mainProductMap.uomDesc = quantityUom.description; + mainProducts.add(mainProductMap); + } + } + + // get alternative product price when product doesn't have any feature + jsBuf = new StringBuffer(); + jsBuf.append("<script language=\"JavaScript\" type=\"text/javascript\">"); + + // make a list of variant sku with requireAmount + virtualVariantsRes = dispatcher.runSync("getAssociatedProducts", [productIdTo : productId, type : "ALTERNATIVE_PACKAGE", checkViewAllow : true, prodCatalogId : categoryId]); + virtualVariants = virtualVariantsRes.assocProducts; + // Format to apply the currency code to the variant price in the javascript + if (productStore) { + localeString = productStore.defaultLocaleString; + if (localeString) { + locale = UtilMisc.parseLocale(localeString); + } + } + variantPriceList = []; + numberFormat = NumberFormat.getCurrencyInstance(locale); + + if(virtualVariants){ + amt = new StringBuffer(); + // Create the javascript to return the price for each variant + variantPriceJS = new StringBuffer(); + variantPriceJS.append("function getVariantPrice(sku) { "); + + virtualVariants.each { virtualAssoc -> + virtual = virtualAssoc.getRelatedOne("MainProduct"); + // Get price from a virtual product + priceContext.product = virtual; + if (cart.isSalesOrder()) { + // sales order: run the "calculateProductPrice" service + virtualPriceMap = dispatcher.runSync("calculateProductPrice", priceContext); + BigDecimal calculatedPrice = (BigDecimal)virtualPriceMap.get("price"); + // Get the minimum quantity for variants if MINIMUM_ORDER_PRICE is set for variants. + variantPriceList.add(virtualPriceMap); + } else { + virtualPriceMap = dispatcher.runSync("calculatePurchasePrice", priceContext); + } + variantPriceJS.append(" if (sku == \"" + virtual.productId + "\") return \"" + numberFormat.format(virtualPriceMap.basePrice) + "\"; "); + } + variantPriceJS.append(" } "); + + context.variantPriceList = variantPriceList; + jsBuf.append(amt.toString()); + jsBuf.append(variantPriceJS.toString()); + jsBuf.append("</script>"); + context.virtualJavaScript = jsBuf; + } + } + context.mainProducts = mainProducts; } // get the average rating @@ -151,4 +219,4 @@ sizeProductFeatureAndAppls = delegator.f context.product = product; context.categoryId = categoryId; context.productReviews = reviews; -context.sizeProductFeatureAndAppls = sizeProductFeatureAndAppls; +context.sizeProductFeatureAndAppls = sizeProductFeatureAndAppls; \ No newline at end of file Modified: ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productsummary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productsummary.ftl?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productsummary.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productsummary.ftl Fri Dec 24 06:53:27 2010 @@ -16,6 +16,41 @@ KIND, either express or implied. See th specific language governing permissions and limitations under the License. --> +${virtualJavaScript?if_exists} +<script type="text/javascript"> +<!-- + function displayProductVirtualId(variantId, virtualProductId, pForm) { + if(variantId){ + pForm.product_id.value = variantId; + }else{ + pForm.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); + } + + var priceElem = document.getElementById('variant_price_display'); + var price = getVariantPrice(variantId); + var priceTxt = null; + if(price){ + priceTxt = document.createTextNode(price); + }else{ + priceTxt = document.createTextNode(''); + } + + if(priceElem.hasChildNodes()) { + priceElem.replaceChild(priceTxt, priceElem.firstChild); + } else { + priceElem.appendChild(priceTxt); + } + } +//--> +</script> <#if product?exists> <#-- variable setup --> <#assign productUrl><@ofbizCatalogUrl productId=product.productId currentCategoryId=categoryId/></#assign> @@ -80,9 +115,22 @@ under the License. <input type="text" size="5" name="quantity" value="1"/> <input type="hidden" name="clearSearch" value="N"/> <a href="javascript:document.the${requestAttributes.formNamePrefix?if_exists}${requestAttributes.listIndex?if_exists}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> + <#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> + </#if> </form> - - <#if prodCatMem?exists && prodCatMem.quantity?exists && 0.00 < prodCatMem.quantity?double> + + <#if prodCatMem?exists && prodCatMem.quantity?exists && 0.00 < prodCatMem.quantity?double>222 <form method="post" action="<@ofbizUrl>additem</@ofbizUrl>" name="the${requestAttributes.formNamePrefix?if_exists}${requestAttributes.listIndex?if_exists}defaultform" style="margin: 0;"> <input type="hidden" name="add_product_id" value="${prodCatMem.productId?if_exists}"/> <input type="hidden" name="quantity" value="${prodCatMem.quantity?if_exists}"/> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java Fri Dec 24 06:53:27 2010 @@ -40,6 +40,7 @@ import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.config.ProductConfigWrapper; import org.ofbiz.product.config.ProductConfigWrapper.ConfigOption; @@ -1125,12 +1126,21 @@ nextProd: return variantProductId; } - public static boolean isAlternativePacking(Delegator delegator, String productId, String originalVirtualProductId) { + public static boolean isAlternativePacking(Delegator delegator, String productId, String virtualVariantId) { boolean isAlternativePacking = false; - if(productId != null && originalVirtualProductId != null){ + if(productId != null || virtualVariantId != null){ List<GenericValue> alternativePackingProds = null; try { - alternativePackingProds = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", originalVirtualProductId , "productIdTo", productId, "productAssocTypeId", "ALTERNATIVE_PACKAGE")); + List<EntityCondition> condList = FastList.newInstance(); + + if (UtilValidate.isNotEmpty(productId)) { + condList.add(EntityCondition.makeCondition("productIdTo", productId)); + } + if (UtilValidate.isNotEmpty(virtualVariantId)) { + condList.add(EntityCondition.makeCondition("productId", virtualVariantId)); + } + condList.add(EntityCondition.makeCondition("productAssocTypeId", "ALTERNATIVE_PACKAGE")); + alternativePackingProds = delegator.findList("ProductAssoc", EntityCondition.makeCondition(condList, EntityOperator.AND), null, null, null, true); if(UtilValidate.isNotEmpty(alternativePackingProds)) isAlternativePacking = true; } catch (GenericEntityException e) { Debug.logWarning(e, "Could not found alternative product: " + e.getMessage(), module); @@ -1138,4 +1148,27 @@ nextProd: } return isAlternativePacking; } + + public static String getOriginalProductId(Delegator delegator, String productId){ + boolean isAlternativePacking = isAlternativePacking(delegator, null, productId); + if (isAlternativePacking) { + List<GenericValue> productAssocs = null; + try { + productAssocs = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", productId , "productAssocTypeId", "ALTERNATIVE_PACKAGE")); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + productAssocs = EntityUtil.filterByDate(productAssocs); + + if (productAssocs != null) { + GenericValue productAssoc = EntityUtil.getFirst(productAssocs); + return productAssoc.getString("productIdTo"); + } else { + return null; + } + }else{ + return null; + } + + } } Modified: ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml (original) +++ ofbiz/trunk/specialpurpose/ecommerce/data/DemoProduct.xml Fri Dec 24 06:53:27 2010 @@ -999,4 +999,10 @@ under the License. <ProductPrice productId="WG-9943-S4-BX2" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2000-01-01 00:00:00.0" price="800.0" createdDate="2000-01-01 00:00:00.0"/> <ProductPrice productId="WG-9943-S4-BX5" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2000-01-01 00:00:00.0" price="2000.0" createdDate="2000-01-01 00:00:00.0"/> + <Product productId="WG-1111-BX2" productTypeId="FINISHED_GOOD" primaryProductCategoryId="20111" productName="Micro Chrome Widget" internalName="Micro Chrome Widget" description="Micro Widget - Chrome Colored" longDescription="This micro chrome widget makes a perfect gift. This one is so small that it floats in air." isVirtual="Y" isVariant="Y" quantityIncluded="50.0" weight="2.0" piecesIncluded="2" quantityUomId="OTH_box"/> + <Product productId="WG-1111-BX4" productTypeId="FINISHED_GOOD" primaryProductCategoryId="20111" productName="Micro Chrome Widget" internalName="Micro Chrome Widget" description="Micro Widget - Chrome Colored" longDescription="This micro chrome widget makes a perfect gift. This one is so small that it floats in air." isVirtual="Y" isVariant="Y" quantityIncluded="50.0" weight="2.0" piecesIncluded="4" quantityUomId="OTH_box"/> + <ProductAssoc productId="WG-1111-BX2" productIdTo="WG-1111" productAssocTypeId="ALTERNATIVE_PACKAGE" fromDate="2000-01-01 00:00:00.0"/> + <ProductAssoc productId="WG-1111-BX4" productIdTo="WG-1111" productAssocTypeId="ALTERNATIVE_PACKAGE" fromDate="2000-01-01 00:00:00.0"/> + <ProductPrice productId="WG-1111-BX2" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2001-05-13 12:00:00.0" price="110.0" createdDate="2001-05-13 12:00:00.0" createdByUserLogin="admin" lastModifiedDate="2001-05-13 12:00:00.0" lastModifiedByUserLogin="admin"/> + <ProductPrice productId="WG-1111-BX4" productPricePurposeId="PURCHASE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2001-05-13 12:00:00.0" price="200.0" createdDate="2001-05-13 12:00:00.0" createdByUserLogin="admin" lastModifiedDate="2001-05-13 12:00:00.0" lastModifiedByUserLogin="admin"/> </entity-engine-xml> Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl?rev=1052458&r1=1052457&r2=1052458&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl (original) +++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/productdetail.ftl Fri Dec 24 06:53:27 2010 @@ -22,6 +22,7 @@ under the License. <#-- virtual product javascript --> ${virtualJavaScript?if_exists} +${virtualVariantJavaScript?if_exists} <script type="text/javascript"> //<![CDATA[ var detailImageUrl = null; @@ -269,7 +270,13 @@ ${virtualJavaScript?if_exists} </#if> function displayProductVirtualVariantId(variantId) { - document.addform.product_id.value = variantId; + if(variantId){ + document.addform.product_id.value = variantId; + }else{ + document.addform.product_id.value = ''; + variantId = ''; + } + var elem = document.getElementById('product_id_display'); var txt = document.createTextNode(variantId); if(elem.hasChildNodes()) { @@ -277,7 +284,20 @@ ${virtualJavaScript?if_exists} } else { elem.appendChild(txt); } - setVariantPrice(variantId); + + var priceElem = document.getElementById('variant_price_display'); + var price = getVariantPrice(variantId); + var priceTxt = null; + if(price){ + priceTxt = document.createTextNode(price); + }else{ + priceTxt = document.createTextNode(''); + } + if(priceElem.hasChildNodes()) { + priceElem.replaceChild(priceTxt, priceElem.firstChild); + } else { + priceElem.appendChild(priceTxt); + } } //]]> </script> @@ -584,6 +604,19 @@ ${virtualJavaScript?if_exists} </#if> <#else> <input type="hidden" name="add_product_id" value="${product.productId}" /> + <#if mainProducts?has_content> + <input type="hidden" name="product_id" value=""/> + <select name="productVariantId" onchange="javascript:displayProductVirtualVariantId(this.value);"> + <option value="">Select Unit Of Measure</option> + <#list mainProducts as mainProduct> + <option value="${mainProduct.productId}">${mainProduct.uomDesc} : ${mainProduct.piecesIncluded}</option> + </#list> + </select><br/> + <div> + <strong><span id="product_id_display"> </span></strong> + <strong><div id="variant_price_display"> </div></strong> + </div> + </#if> <#if (availableInventory?exists) && (availableInventory <= 0)> <#assign inStock = false /> </#if> |
Free forum by Nabble | Edit this page |