svn commit: r450107 - /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

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

svn commit: r450107 - /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

jonesde
Author: jonesde
Date: Tue Sep 26 09:28:22 2006
New Revision: 450107

URL: http://svn.apache.org/viewvc?view=rev&rev=450107
Log:
Added a method to explode a list of cart items, or in other words unitize them, or in other words for each item of X quantity, create X items of 1 quantity

Modified:
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

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=450107&r1=450106&r2=450107
==============================================================================
--- 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 Tue Sep 26 09:28:22 2006
@@ -2984,20 +2984,43 @@
     }
 
     private void explodeItems(LocalDispatcher dispatcher) {
+        if (dispatcher == null) return;
         synchronized (cartLines) {
-            if (dispatcher != null) {
-                List cartLineItems = new LinkedList(cartLines);
-                Iterator itemIter = cartLineItems.iterator();
+            List cartLineItems = new LinkedList(cartLines);
+            Iterator itemIter = cartLineItems.iterator();
 
-                while (itemIter.hasNext()) {
-                    ShoppingCartItem item = (ShoppingCartItem) itemIter.next();
+            while (itemIter.hasNext()) {
+                ShoppingCartItem item = (ShoppingCartItem) itemIter.next();
 
-                    Debug.logInfo("Item qty: " + item.getQuantity(), module);
-                    try {
-                        item.explodeItem(this, dispatcher);
-                    } catch (CartItemModifyException e) {
-                        Debug.logError(e, "Problem exploding item! Item not exploded.", module);
-                    }
+                //Debug.logInfo("Item qty: " + item.getQuantity(), module);
+                try {
+                    item.explodeItem(this, dispatcher);
+                } catch (CartItemModifyException e) {
+                    Debug.logError(e, "Problem exploding item! Item not exploded.", module);
+                }
+            }
+        }
+    }
+
+    /**
+     * Does an "explode", or "unitize" operation on a list of cart items.
+     * Resulting state for each item with quantity X is X items of quantity 1.
+     *
+     * @param shoppingCartItems
+     * @param dispatcher
+     */
+    public void explodeItems(List shoppingCartItems, LocalDispatcher dispatcher) {
+        if (dispatcher == null) return;
+        synchronized (cartLines) {
+            Iterator itemIter = shoppingCartItems.iterator();
+            while (itemIter.hasNext()) {
+                ShoppingCartItem item = (ShoppingCartItem) itemIter.next();
+
+                //Debug.logInfo("Item qty: " + item.getQuantity(), module);
+                try {
+                    item.explodeItem(this, dispatcher);
+                } catch (CartItemModifyException e) {
+                    Debug.logError(e, "Problem exploding (unitizing) item! Item not exploded.", module);
                 }
             }
         }