Author: jleroux
Date: Sun Oct 14 05:04:24 2007
New Revision: 584531
URL: http://svn.apache.org/viewvc?rev=584531&view=rev
Log:
A modified patch from Eric Crawford "Customer must add a virtual product to the
cart to get the price of that product."
(https://issues.apache.org/jira/browse/OFBIZ-618) - OFBIZ-618
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh
ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl
Modified:
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.bsh?rev=584531&r1=584530&r2=584531&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.bsh
Sun Oct 14 05:04:24 2007
@@ -22,6 +22,8 @@
* should not contain order component's specific code.
*/
+import java.text.NumberFormat;
+
import org.ofbiz.base.util.*;
import org.ofbiz.entity.*;
import org.ofbiz.entity.condition.*;
@@ -205,7 +207,7 @@
// get the days to ship
- facilityId = productStore.getString("inventoryFacilityId");
+ 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"));
@@ -379,22 +381,38 @@
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);
+ }
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(" } ");
}
jsBuf.append(amt.toString());
+ jsBuf.append(variantPriceJS.toString());
jsBuf.append("</script>");
context.put("virtualJavaScript", jsBuf.toString());
}
}
-
-
}
// get product associations
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl?rev=584531&r1=584530&r2=584531&view=diff
==============================================================================
---
ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl
(original)
+++
ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl
Sun Oct 14 05:04:24 2007
@@ -32,12 +32,41 @@
document.addform.quantity.disabled = true;
var elem = document.getElementById('product_id_display');
var txt = document.createTextNode('');
- elem.replaceChild(txt, elem.firstChild);
+ 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);
- elem.replaceChild(txt, elem.firstChild);
+ if(elem.hasChildNodes()) {
+ elem.replaceChild(txt, elem.firstChild);
+ } else {
+ elem.appendChild(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 isVirtual(product) {
@@ -124,6 +153,9 @@
// set the product ID to NULL to trigger the alerts
setAddProductId('NULL');
+
+ // set the variant price to NULL
+ setVariantPrice('NULL');
} else {
// this is the final selection -- locate the selected index of the
last selection
var indexSelected =
document.forms["addform"].elements[name].selectedIndex;
@@ -133,6 +165,9 @@
// set the product ID
setAddProductId(sku);
+
+ // set the variant price
+ setVariantPrice(sku);
// check for amount box
toggleAmt(checkAmtReq(sku));
@@ -370,7 +405,8 @@
<input type="hidden" name="product_id"
value="${product.productId}"/>
<input type="hidden" name="add_product_id" value="NULL"/>
<div class="tabletext">
- <b><span id="product_id_display"> </span></b>
+ <b><span id="product_id_display"> </span></b>
+ <b><div id="variant_price_display"> </div></b>
</div>
<#else>
<input type="hidden" name="product_id"
value="${product.productId}"/>