svn commit: r441498 - in /incubator/ofbiz/trunk/applications/order: src/org/ofbiz/order/shoppingcart/ShoppingCart.java src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java webapp/ordermgr/WEB-INF/controller.xml

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

svn commit: r441498 - in /incubator/ofbiz/trunk/applications/order: src/org/ofbiz/order/shoppingcart/ShoppingCart.java src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java webapp/ordermgr/WEB-INF/controller.xml

jacopoc
Author: jacopoc
Date: Fri Sep  8 07:04:51 2006
New Revision: 441498

URL: http://svn.apache.org/viewvc?view=rev&rev=441498
Log:
Completed quick purchase order creation with the quick checkout process (using default values).

Modified:
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
    incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?view=diff&rev=441498&r1=441497&r2=441498
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Fri Sep  8 07:04:51 2006
@@ -49,6 +49,7 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.party.contact.ContactHelper;
+import org.ofbiz.party.contact.ContactMechWorker;
 import org.ofbiz.order.order.OrderReadHelper;
 import org.ofbiz.order.finaccount.FinAccountHelper;
 import org.ofbiz.order.shoppingcart.product.ProductPromoWorker;
@@ -2164,25 +2165,67 @@
     public void setDefaultCheckoutOptions(LocalDispatcher dispatcher) {
         // skip the add party screen
         this.setAttribute("addpty", "Y");
-        // set as the default shipping location the first from the list of available shipping locations
-        if (this.getPartyId() != null && !this.getPartyId().equals("_NA_")) {
-            try {
-                GenericValue orderParty = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", this.getPartyId()));
-                Collection shippingContactMechList = ContactHelper.getContactMech(orderParty, "SHIPPING_LOCATION", "POSTAL_ADDRESS", false);
-                if (shippingContactMechList != null && shippingContactMechList.size() > 0) {
-                    GenericValue shippingContactMech = (GenericValue)(shippingContactMechList.iterator()).next();
-                    this.setShippingContactMechId(shippingContactMech.getString("contactMechId"));
+        if (getOrderType().equals("SALES_ORDER")) {
+            // checkout options for sales orders
+            // set as the default shipping location the first from the list of available shipping locations
+            if (this.getPartyId() != null && !this.getPartyId().equals("_NA_")) {
+                try {
+                    GenericValue orderParty = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", this.getPartyId()));
+                    Collection shippingContactMechList = ContactHelper.getContactMech(orderParty, "SHIPPING_LOCATION", "POSTAL_ADDRESS", false);
+                    if (shippingContactMechList != null && shippingContactMechList.size() > 0) {
+                        GenericValue shippingContactMech = (GenericValue)(shippingContactMechList.iterator()).next();
+                        this.setShippingContactMechId(shippingContactMech.getString("contactMechId"));
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, "Error setting shippingContactMechId in setDefaultCheckoutOptions() method.", module);
                 }
-            } catch (GenericEntityException e) {
-                Debug.logError(e, "Error setting shippingContactMechId in setDefaultCheckoutOptions() method.", module);
             }
-        }
-        // set the default shipment method
-        ShippingEstimateWrapper shipEstimateWrapper = org.ofbiz.order.shoppingcart.shipping.ShippingEstimateWrapper.getWrapper(dispatcher, this, 0);
-        GenericValue carrierShipmentMethod = EntityUtil.getFirst(shipEstimateWrapper.getShippingMethods());
-        if (carrierShipmentMethod != null) {
-            this.setShipmentMethodTypeId(carrierShipmentMethod.getString("shipmentMethodTypeId"));
-            this.setCarrierPartyId(carrierShipmentMethod.getString("partyId"));
+            // set the default shipment method
+            ShippingEstimateWrapper shipEstimateWrapper = org.ofbiz.order.shoppingcart.shipping.ShippingEstimateWrapper.getWrapper(dispatcher, this, 0);
+            GenericValue carrierShipmentMethod = EntityUtil.getFirst(shipEstimateWrapper.getShippingMethods());
+            if (carrierShipmentMethod != null) {
+                this.setShipmentMethodTypeId(carrierShipmentMethod.getString("shipmentMethodTypeId"));
+                this.setCarrierPartyId(carrierShipmentMethod.getString("partyId"));
+            }
+        } else {
+            // checkout options for purchase orders
+            // TODO: should we select a default agreement? For now we don't do this.
+            // skip the order terms selection step
+            this.setOrderTermSet(true);
+            // 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;
+                                }
+                            }
+                        }
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, "Error setting shippingContactMechId in setDefaultCheckoutOptions() method.", module);
+                }
+            }
+            // shipping options
+            this.setShipmentMethodTypeId(0, "NO_SHIPPING");
+            this.setCarrierPartyId(0, "_NA_");
+            this.setShippingInstructions(0, "");
+            this.setGiftMessage(0, "");
+            this.setMaySplit(0, new Boolean(true));
+            this.setIsGift(0, new Boolean(false));
+            //this.setInternalCode(internalCode);
         }
     }
 

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?view=diff&rev=441498&r1=441497&r2=441498
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Fri Sep  8 07:04:51 2006
@@ -477,14 +477,20 @@
 
         cart.setOrderType("PURCHASE_ORDER");
         
-        // Set the cart's default checkout options for a quick checkout
-        // TODO: the code below need to be enhanced to handle po
-        //cart.setDefaultCheckoutOptions(dispatcher);
-
         session.setAttribute("shoppingCart", cart);
         session.setAttribute("productStoreId", cart.getProductStoreId());
         session.setAttribute("orderMode", cart.getOrderType());
         session.setAttribute("orderPartyId", cart.getOrderPartyId());
+
+        return "success";
+    }
+
+    public static String quickCheckoutOrderWithDefaultOptions(HttpServletRequest request, HttpServletResponse response) {
+        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
+        ShoppingCart cart = getCartObject(request);
+
+        // Set the cart's default checkout options for a quick checkout
+        cart.setDefaultCheckoutOptions(dispatcher);
 
         return "success";
     }

Modified: incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?view=diff&rev=441498&r1=441497&r2=441498
==============================================================================
--- incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original)
+++ incubator/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Fri Sep  8 07:04:51 2006
@@ -398,6 +398,12 @@
         <response name="success" type="request" value="orderentry"/>
         <response name="error" type="request" value="orderentry"/>
     </request-map>
+    <request-map uri="quickAddRequirementsToCart">
+        <security https="true" auth="true"/>
+        <event type="java" path="org.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="addToCartBulkRequirements"/>
+        <response name="success" type="request" value="quickCheckoutOrderWithDefaultOptions"/>
+        <response name="error" type="request" value="orderentry"/>
+    </request-map>
     <request-map uri="FindQuoteForCart">
         <security https="true" auth="true"/>
         <response name="success" type="view" value="FindQuoteForCart"/>
@@ -1007,8 +1013,14 @@
     <request-map uri="quickPurchaseOrderEntry">
         <security https="true" auth="true"/>
         <event type="java" path="org.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="quickInitPurchaseOrder"/>
-        <response name="success" type="request" value="addRequirementsToCart"/>
+        <response name="success" type="request" value="quickAddRequirementsToCart"/>
         <response name="error" type="view" value="ApprovedProductRequirements"/>
+    </request-map>
+    <request-map uri="quickCheckoutOrderWithDefaultOptions">
+        <security https="true" auth="true"/>
+        <event type="java" path="org.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="quickCheckoutOrderWithDefaultOptions"/>
+        <response name="success" type="request" value="confirmOrder"/>
+        <response name="error" type="view" value="orderentry"/>
     </request-map>
 
     <request-map uri="RequirementsForSupplier">