svn commit: r566369 - in /ofbiz/trunk/applications/order: src/org/ofbiz/order/shoppingcart/ShoppingCart.java src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java webapp/ordermgr/requirement/RequirementForms.xml

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

svn commit: r566369 - in /ofbiz/trunk/applications/order: src/org/ofbiz/order/shoppingcart/ShoppingCart.java src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java webapp/ordermgr/requirement/RequirementForms.xml

sichen
Author: sichen
Date: Wed Aug 15 15:41:37 2007
New Revision: 566369

URL: http://svn.apache.org/viewvc?view=rev&rev=566369
Log:
OFBIZ-1205 contribution from Leon Torres.  Fixes unresolved issue of how to select a facilityId for default purchase order shopping cart.

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
    ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml

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?view=diff&rev=566369&r1=566368&r2=566369
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Wed Aug 15 15:41:37 2007
@@ -2345,27 +2345,21 @@
             // set as the default shipping location the first from the list of available shipping locations
             String companyId = this.getBillToCustomerPartyId();
             if (companyId != null) {
-                try {
-                    List facilities = delegator.findByAndCache("Facility", UtilMisc.toMap("ownerPartyId", companyId));
-                    // TODO: improve code here to select the best ship to facility (from requirements?);
-                    //       for now, we consider the first one
-                    GenericValue facility = EntityUtil.getFirst(facilities);
-                    if (facility != null) {
-                        List facilityContactMechValueMaps = ContactMechWorker.getFacilityContactMechValueMaps(delegator, facility.getString("facilityId"), false, null);
-                        if (facilityContactMechValueMaps != null) {
-                            Iterator facilityContactMechValueMapsIt = facilityContactMechValueMaps.iterator();
-                            while (facilityContactMechValueMapsIt.hasNext()) {
-                                Map facilityContactMechValueMap = (Map)facilityContactMechValueMapsIt.next();
-                                if (facilityContactMechValueMap.get("postalAddress") != null) {
-                                    GenericValue postalAddress = (GenericValue)facilityContactMechValueMap.get("postalAddress");
-                                    this.setShippingContactMechId(0, postalAddress.getString("contactMechId"));
-                                    break;
-                                }
+                // the facilityId should be set prior to triggering default options, otherwise we do not set up facility information
+                String defaultFacilityId = getFacilityId();
+                if (defaultFacilityId != null) {
+                    List facilityContactMechValueMaps = ContactMechWorker.getFacilityContactMechValueMaps(delegator, defaultFacilityId, false, null);
+                    if (facilityContactMechValueMaps != null) {
+                        Iterator facilityContactMechValueMapsIt = facilityContactMechValueMaps.iterator();
+                        while (facilityContactMechValueMapsIt.hasNext()) {
+                            Map facilityContactMechValueMap = (Map)facilityContactMechValueMapsIt.next();
+                            if (facilityContactMechValueMap.get("postalAddress") != null) {
+                                GenericValue postalAddress = (GenericValue)facilityContactMechValueMap.get("postalAddress");
+                                this.setShippingContactMechId(0, postalAddress.getString("contactMechId"));
+                                break;
                             }
                         }
                     }
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, "Error setting shippingContactMechId in setDefaultCheckoutOptions() method.", module);
                 }
             }
             // shipping options

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?view=diff&rev=566369&r1=566368&r2=566369
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Wed Aug 15 15:41:37 2007
@@ -408,6 +408,12 @@
         } catch (NumberFormatException e) {
             //throw new EventHandlerException("Invalid value for _rowCount");
         }
+
+        // assume that the facility is the same for all requirements
+        String facilityId = (String) context.get("facilityId_o_0");
+        if (UtilValidate.isNotEmpty(facilityId)) {
+            cart.setFacilityId(facilityId);
+        }
         
         // now loop throw the rows and prepare/invoke the service for each
         for (int i = 0; i < rowCount; i++) {

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml?view=diff&rev=566369&r1=566368&r2=566369
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml Wed Aug 15 15:41:37 2007
@@ -291,6 +291,7 @@
         <field name="productId" widget-style="buttontext">
             <hyperlink also-hidden="true" target-type="inter-app" description="${productId}" target="/catalog/control/EditProductInventoryItems?productId=${productId}" target-window="top"/>
         </field>
+        <field name="facilityId"><hidden value="${parameters.facilityId}"/></field>
         <field name="internalName" entry-name="productId">
             <display-entity entity-name="Product" key-field-name="productId" description="${internalName}"/>
         </field>