svn commit: r727381 - in /ofbiz/trunk/applications: ecommerce/script/org/ofbiz/ecommerce/customer/ ecommerce/webapp/ecommerce/images/ order/src/org/ofbiz/order/shoppingcart/ order/src/org/ofbiz/order/shoppingcart/shipping/ product/entitydef/ product/se...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r727381 - in /ofbiz/trunk/applications: ecommerce/script/org/ofbiz/ecommerce/customer/ ecommerce/webapp/ecommerce/images/ order/src/org/ofbiz/order/shoppingcart/ order/src/org/ofbiz/order/shoppingcart/shipping/ product/entitydef/ product/se...

ashish-18
Author: ashish
Date: Wed Dec 17 05:53:49 2008
New Revision: 727381

URL: http://svn.apache.org/viewvc?rev=727381&view=rev
Log:
Patch from Arun Patidar & Jyotsna Rathore "Calculate shipping cost estimates based on productStoreShipMethId." (OFBIZ-2082).

Thanks Jyotsna & Arun for your contribution.
Special thanks to Jacopo for his help in reviewing the content.

Modified:
    ofbiz/trunk/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
    ofbiz/trunk/applications/ecommerce/webapp/ecommerce/images/checkoutProcess.js
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
    ofbiz/trunk/applications/product/entitydef/entitymodel_shipment.xml
    ofbiz/trunk/applications/product/servicedef/services_shipment.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java

Modified: ofbiz/trunk/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml (original)
+++ ofbiz/trunk/applications/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml Wed Dec 17 05:53:49 2008
@@ -1066,6 +1066,9 @@
             </if-compare-field>
             <set field="shippingOptionMap.shippingMethod" from-field="shippingMethod"/>
             <set field="shippingOptionMap.shippingDesc" from-field="shippingDesc"/>
+            <if-not-empty field="carrierShipmentMethod.productStoreShipMethId">
+                <set field="shippingOptionMap.productStoreShipMethId" from-field="carrierShipmentMethod.productStoreShipMethId"/>
+            </if-not-empty>
             <field-to-list field-name="shippingOptionMap" list-name="shippingOptions"/>
             <clear-field field-name="shippingOptionMap"/>
         </iterate>
@@ -1078,15 +1081,23 @@
             shippingMethod = parameters.get("shipMethod");
             if(shippingMethod != null) {
                 shipmentMethodTypeId = shippingMethod.substring(0, shippingMethod.indexOf("@"));
-                carrierPartyId = shippingMethod.substring(shippingMethod.indexOf("@")+1);
+                if (shippingMethod.indexOf(":") != -1) {
+                    carrierPartyId = shippingMethod.substring(shippingMethod.indexOf("@")+1, shippingMethod.indexOf(":"));
+                    productStoreShipMethId =  shippingMethod.substring(shippingMethod.indexOf(":")+1);
+                    parameters.put("productStoreShipMethId", productStoreShipMethId);
+                } else {
+                    carrierPartyId = shippingMethod.substring(shippingMethod.indexOf("@")+1);
+                }
                 parameters.put("shipmentMethodTypeId", shipmentMethodTypeId);
                 parameters.put("carrierPartyId", carrierPartyId);
             }
         ]]></call-bsh>
         <set field="shipmentMethodTypeId" from-field="parameters.shipmentMethodTypeId"/>
         <set field="carrierPartyId" from-field="parameters.carrierPartyId"/>
+        <set field="productStoreShipMethId" from-field="parameters.productStoreShipMethId"/>
         <log level="info" message=" shipmentMethodTypeId is ${shipmentMethodTypeId} "/>
         <log level="info" message=" carrierPartyId is ${carrierPartyId}"/>
+        <log level="info" message=" productStoreShipMethId is ${productStoreShipMethId}"/>
         
         <entity-one entity-name="CarrierAndShipmentMethod" value-name="shipmentMethod">
             <field-map field-name="shipmentMethodTypeId" env-name="shipmentMethodTypeId"/>
@@ -1105,6 +1116,9 @@
         <call-object-method obj-field-name="shoppingCart" method-name="setCarrierPartyId">
             <field field-name="carrierPartyId"/>
         </call-object-method>
+        <call-object-method obj-field-name="shoppingCart" method-name="setProductStoreShipMethId">
+            <field field-name="productStoreShipMethId"/>
+        </call-object-method>
         <call-object-method  obj-field-name="shoppingCart" method-name="getCurrency" ret-field-name="isoCode"/>
         <set field="dispatcher" from-field="parameters.dispatcher" type="Object"/>
         <set field="delegator" from-field="parameters.delegator" type="Object"/>

Modified: ofbiz/trunk/applications/ecommerce/webapp/ecommerce/images/checkoutProcess.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/ecommerce/webapp/ecommerce/images/checkoutProcess.js?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/ecommerce/webapp/ecommerce/images/checkoutProcess.js (original)
+++ ofbiz/trunk/applications/ecommerce/webapp/ecommerce/images/checkoutProcess.js Wed Dec 17 05:53:49 2008
@@ -289,7 +289,11 @@
                     isShipStepValidate = true;
                     shipOptions = data.shippingOptions;
                     shipOptions.each( function(shipOption) {
-                        optionList.push("<option value = " + shipOption.shippingMethod + " > " + shipOption.shippingDesc + " </option>");
+                        if (shipOption.productStoreShipMethId){
+                            optionList.push("<option value = " + shipOption.shippingMethod + ":" + shipOption.productStoreShipMethId + " > " + shipOption.shippingDesc  + " </option>");
+                        } else {
+                            optionList.push("<option value = " + shipOption.shippingMethod + " > " + shipOption.shippingDesc  + " </option>");    
+                        }
                     });
                     $('shipMethod').update(optionList);
                     result = true;

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Wed Dec 17 05:53:49 2008
@@ -77,6 +77,7 @@
     private String quoteId = null;
     private String workEffortId = null;
     private long nextItemSeq = 1;
+    private String productStoreShipMethId = null;
 
     private String defaultItemDeliveryDate = null;
     private String defaultItemComment = null;
@@ -2309,6 +2310,14 @@
         return this.getCarrierPartyId(0);
     }
 
+    public String getProductStoreShipMethId() {
+        return productStoreShipMethId;
+    }  
+
+    public void setProductStoreShipMethId(String productStoreShipMethId) {
+        this.productStoreShipMethId = productStoreShipMethId;
+    }
+
     public void setShipGroupFacilityId(int idx, String facilityId) {
         CartShipInfo csi = this.getShipInfo(idx);
         csi.facilityId = facilityId;

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java Wed Dec 17 05:53:49 2008
@@ -93,11 +93,12 @@
                 String shippingMethodTypeId = shipMethod.getString("shipmentMethodTypeId");
                 String carrierRoleTypeId = shipMethod.getString("roleTypeId");
                 String carrierPartyId = shipMethod.getString("partyId");
+                String productStoreShipMethId = shipMethod.getString("productStoreShipMethId");
                 String shippingCmId = shippingAddress != null ? shippingAddress.getString("contactMechId") : null;
 
                 Map estimateMap = ShippingEvents.getShipGroupEstimate(dispatcher, delegator, "SALES_ORDER",
                         shippingMethodTypeId, carrierPartyId, carrierRoleTypeId, shippingCmId, productStoreId,
-                        supplierPartyId, shippableItemInfo, shippableWeight, shippableQuantity, shippableTotal, partyId);
+                        supplierPartyId, shippableItemInfo, shippableWeight, shippableQuantity, shippableTotal, partyId, productStoreShipMethId);
 
                 if (!ServiceUtil.isError(estimateMap)) {
                     Double shippingTotal = (Double) estimateMap.get("shippingTotal");

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java Wed Dec 17 05:53:49 2008
@@ -97,10 +97,11 @@
 
         String shipmentMethodTypeId = cart.getShipmentMethodTypeId(groupNo);
         String carrierPartyId = cart.getCarrierPartyId(groupNo);
+        String productStoreShipMethId = cart.getProductStoreShipMethId();
 
         return getShipGroupEstimate(dispatcher, delegator, cart.getOrderType(), shipmentMethodTypeId, carrierPartyId, null,
                 cart.getShippingContactMechId(groupNo), cart.getProductStoreId(), cart.getSupplierPartyId(groupNo), cart.getShippableItemInfo(groupNo),
-                cart.getShippableWeight(groupNo), cart.getShippableQuantity(groupNo), cart.getShippableTotal(groupNo), cart.getPartyId());
+                cart.getShippableWeight(groupNo), cart.getShippableQuantity(groupNo), cart.getShippableTotal(groupNo), cart.getPartyId(), productStoreShipMethId);
     }
 
     public static Map getShipEstimate(LocalDispatcher dispatcher, GenericDelegator delegator, OrderReadHelper orh, String shipGroupSeqId) {
@@ -116,6 +117,7 @@
         String carrierRoleTypeId = shipGroup.getString("carrierRoleTypeId");
         String carrierPartyId = shipGroup.getString("carrierPartyId");
         String supplierPartyId = shipGroup.getString("supplierPartyId");
+        String productStoreShipMethId = shipGroup.getString("productStoreShipMethId");
 
         GenericValue shipAddr = orh.getShippingAddress(shipGroupSeqId);
         if (shipAddr == null) {
@@ -130,23 +132,23 @@
         }
         return getShipGroupEstimate(dispatcher, delegator, orh.getOrderTypeId(), shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId,
                 contactMechId, orh.getProductStoreId(), supplierPartyId, orh.getShippableItemInfo(shipGroupSeqId), orh.getShippableWeight(shipGroupSeqId).doubleValue(),
-                orh.getShippableQuantity(shipGroupSeqId).doubleValue(), orh.getShippableTotal(shipGroupSeqId).doubleValue(), partyId);
+                orh.getShippableQuantity(shipGroupSeqId).doubleValue(), orh.getShippableTotal(shipGroupSeqId).doubleValue(), partyId, productStoreShipMethId);
     }
 
     // version with no support for using the supplier's address as the origin
     public static Map getShipGroupEstimate(LocalDispatcher dispatcher, GenericDelegator delegator, String orderTypeId,
             String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId, String shippingContactMechId,
             String productStoreId, List itemInfo, double shippableWeight, double shippableQuantity,
-            double shippableTotal, String partyId) {
+            double shippableTotal, String partyId, String productStoreShipMethId) {
         return getShipGroupEstimate(dispatcher, delegator, orderTypeId, shipmentMethodTypeId, carrierPartyId,
                 carrierRoleTypeId, shippingContactMechId, productStoreId, null, itemInfo,
-                shippableWeight, shippableQuantity, shippableTotal, partyId);
+                shippableWeight, shippableQuantity, shippableTotal, partyId,productStoreShipMethId);
     }
 
     public static Map getShipGroupEstimate(LocalDispatcher dispatcher, GenericDelegator delegator, String orderTypeId,
             String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId, String shippingContactMechId,
             String productStoreId, String supplierPartyId, List itemInfo, double shippableWeight, double shippableQuantity,
-            double shippableTotal, String partyId) {
+            double shippableTotal, String partyId, String productStoreShipMethId) {
         String standardMessage = "A problem occurred calculating shipping. Fees will be calculated offline.";
         List errorMessageList = new ArrayList();
 
@@ -217,6 +219,7 @@
         serviceFields.put("shippingContactMechId", shippingContactMechId);
         serviceFields.put("shippingOriginContactMechId", shippingOriginContactMechId);
         serviceFields.put("partyId", partyId);
+        serviceFields.put("productStoreShipMethId", productStoreShipMethId);
 
         // call the external shipping service
         try {

Modified: ofbiz/trunk/applications/product/entitydef/entitymodel_shipment.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel_shipment.xml?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/entitydef/entitymodel_shipment.xml (original)
+++ ofbiz/trunk/applications/product/entitydef/entitymodel_shipment.xml Wed Dec 17 05:53:49 2008
@@ -731,9 +731,10 @@
             package-name="org.ofbiz.shipment.shipment"
             title="Shipment Cost Estimate Entity">
       <field name="shipmentCostEstimateId" type="id-ne"></field>
-      <field name="shipmentMethodTypeId" type="id-ne"></field>
-      <field name="carrierPartyId" type="id-ne"></field>
-      <field name="carrierRoleTypeId" type="id-ne"></field>
+      <field name="shipmentMethodTypeId" type="id"></field>
+      <field name="carrierPartyId" type="id"></field>
+      <field name="carrierRoleTypeId" type="id"></field>
+      <field name="productStoreShipMethId" type="id"></field>
       <field name="productStoreId" type="id"></field>
       <field name="partyId" type="id"></field>
       <field name="roleTypeId" type="id"></field>

Modified: ofbiz/trunk/applications/product/servicedef/services_shipment.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_shipment.xml?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_shipment.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_shipment.xml Wed Dec 17 05:53:49 2008
@@ -682,6 +682,7 @@
         <attribute name="shipmentMethodTypeId" type="String" mode="IN" optional="false"/>
         <attribute name="carrierPartyId" type="String" mode="IN" optional="false"/>
         <attribute name="carrierRoleTypeId" type="String" mode="IN" optional="false"/>
+        <attribute name="productStoreShipMethId" type="String" mode="IN" optional="true"/>
         <attribute name="productStoreId" type="String" mode="IN" optional="false"/>
         <attribute name="shippableItemInfo" type="List" mode="IN" optional="false"/>
         <attribute name="shippableWeight" type="Double" mode="IN" optional="false"/>

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java?rev=727381&r1=727380&r2=727381&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java Wed Dec 17 05:53:49 2008
@@ -30,6 +30,8 @@
 import org.ofbiz.entity.GenericDelegator;
 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.EntityListIterator;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.service.DispatchContext;
@@ -207,6 +209,7 @@
         GenericDelegator delegator = dctx.getDelegator();
 
         // prepare the data
+        String productStoreShipMethId = (String) context.get("productStoreShipMethId");
         String productStoreId = (String) context.get("productStoreId");
         String carrierRoleTypeId = (String) context.get("carrierRoleTypeId");
         String carrierPartyId = (String) context.get("carrierPartyId");
@@ -240,10 +243,17 @@
         // get the ShipmentCostEstimate(s)
         Map<String, String> estFields = UtilMisc.toMap("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId,
                 "carrierPartyId", carrierPartyId, "carrierRoleTypeId", carrierRoleTypeId);
-
+        EntityCondition estFieldsCond = EntityCondition.makeCondition(estFields, EntityOperator.AND);
+        
+        if (UtilValidate.isNotEmpty(productStoreShipMethId)) {
+            // if the productStoreShipMethId field is passed, then also get estimates that have the field set
+            List<EntityCondition> condList = UtilMisc.toList(EntityCondition.makeCondition("productStoreShipMethId", EntityOperator.EQUALS, productStoreShipMethId), estFieldsCond);
+            estFieldsCond = EntityCondition.makeCondition(condList, EntityOperator.OR);
+        }
+        
         Collection<GenericValue> estimates = null;
         try {
-            estimates = delegator.findByAnd("ShipmentCostEstimate", estFields);
+            estimates = delegator.findList("ShipmentCostEstimate", estFieldsCond, null, null, null, true);
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError("Unable to locate estimates from database");