You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2011/02/14 20:00:10 UTC

svn commit: r1070606 - in /ofbiz/trunk/applications/order: servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

Author: jaz
Date: Mon Feb 14 19:00:09 2011
New Revision: 1070606

URL: http://svn.apache.org/viewvc?rev=1070606&view=rev
Log:
sometimes just updating order items is not enough, we need the ability to delete the old items before adding in the items currently in the cart; in cases where cancelling an item is not acceptable, this minor fix makes this functionality available if desired (not enabled by default); to enable pass the deleteItems boolean parameter as TRUE

Modified:
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=1070606&r1=1070605&r2=1070606&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Mon Feb 14 19:00:09 2011
@@ -342,6 +342,7 @@ under the License.
         <attribute name="orderId" type="String" mode="INOUT" optional="false"/>
         <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
         <attribute name="calcTax" type="Boolean" mode="IN" optional="true" default-value="true"/>
+        <attribute name="deleteItems" type="Boolean" mode="IN" optional="true" default-value="false"/>
         <!-- <attribute name="locale" type="" mode="IN" optional="false"/> -->
         <attribute name="changeMap" type="Map" mode="IN" optional="false"/>
     </service>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1070606&r1=1070605&r2=1070606&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Feb 14 19:00:09 2011
@@ -3494,7 +3494,7 @@ public class OrderServices {
                                         "itemCommentMap", UtilMisc.<String, Object>toMap("changeComments", changeComments));
         // save all the updated information
         try {
-            saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, changeMap, calcTax);
+            saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, changeMap, calcTax, false);
         } catch (GeneralException e) {
             return ServiceUtil.returnError(e.getMessage());
         }
@@ -3702,7 +3702,7 @@ public class OrderServices {
 
         // save all the updated information
         try {
-            saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, UtilMisc.<String, Object>toMap("itemReasonMap", itemReasonMap, "itemCommentMap", itemCommentMap), calcTax);
+            saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, UtilMisc.<String, Object>toMap("itemReasonMap", itemReasonMap, "itemCommentMap", itemCommentMap), calcTax, false);
         } catch (GeneralException e) {
             return ServiceUtil.returnError(e.getMessage());
         }
@@ -3923,6 +3923,7 @@ public class OrderServices {
         ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");
         Map<String, Object> changeMap = UtilGenerics.checkMap(context.get("changeMap"));
         Locale locale = (Locale) context.get("locale");
+        Boolean deleteItems = (Boolean) context.get("deleteItems");
         Boolean calcTax = (Boolean) context.get("calcTax");
         if (calcTax == null) {
             calcTax = Boolean.TRUE;
@@ -3930,7 +3931,7 @@ public class OrderServices {
 
         Map<String, Object> result = null;
         try {
-            saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, changeMap, calcTax);
+            saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, changeMap, calcTax, deleteItems);
             result = ServiceUtil.returnSuccess();
             //result.put("shoppingCart", cart);
         } catch (GeneralException e) {
@@ -3942,7 +3943,7 @@ public class OrderServices {
         return result;
     }
 
-    private static void saveUpdatedCartToOrder(LocalDispatcher dispatcher, Delegator delegator, ShoppingCart cart, Locale locale, GenericValue userLogin, String orderId, Map<String, Object> changeMap, boolean calcTax) throws GeneralException {
+    private static void saveUpdatedCartToOrder(LocalDispatcher dispatcher, Delegator delegator, ShoppingCart cart, Locale locale, GenericValue userLogin, String orderId, Map<String, Object> changeMap, boolean calcTax, boolean deleteItems) throws GeneralException {
         // get/set the shipping estimates.  if it's a SALES ORDER, then return an error if there are no ship estimates
         int shipGroups = cart.getShipGroupSize();
         for (int gi = 0; gi < shipGroups; gi++) {
@@ -4052,6 +4053,15 @@ public class OrderServices {
         toRemove.addAll(existingPromoCodes);
         toRemove.addAll(existingPromoUses);
         
+        if (deleteItems) {
+            // flag to delete existing order items           
+            try {
+                toRemove.addAll(delegator.findByAnd("OrderItem", "orderId", orderId));
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+            }
+        }
+        
         // set the orderId & other information on all new value objects
         List<String> dropShipGroupIds = FastList.newInstance(); // this list will contain the ids of all the ship groups for drop shipments (no reservations)
         Iterator<GenericValue> tsi = toStore.iterator();