Author: ashish
Date: Sat Dec 20 13:38:06 2014
New Revision: 1646977

URL: http://svn.apache.org/r1646977
Log:
Applied patch from jira issue - OFBIZ-223 - CartShipInfo objects are not 
properly cloned when shopping cart items are exploded.
Thanks Arun for the contribution.

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

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=1646977&r1=1646976&r2=1646977&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
 Sat Dec 20 13:38:06 2014
@@ -3542,7 +3542,17 @@ public class ShoppingCart implements Ite
             for (ShoppingCartItem item : cartLineItems) {
                 //Debug.logInfo("Item qty: " + item.getQuantity(), module);
                 try {
-                    item.explodeItem(this, dispatcher);
+                    int thisIndex = items().indexOf(item);
+                    List<ShoppingCartItem> explodedItems = 
item.explodeItem(this, dispatcher);
+
+                    // Add exploded items into cart with order item sequence 
id and item ship group quantity
+                    for (ShoppingCartItem explodedItem : explodedItems) {
+                        String orderItemSeqId = 
UtilFormatOut.formatPaddedNumber(nextItemSeq, 5);
+                        explodedItem.setOrderItemSeqId(orderItemSeqId);
+                        addItemToEnd(explodedItem);
+                        setItemShipGroupQty(explodedItem, BigDecimal.ONE, 
thisIndex);
+                        nextItemSeq++;
+                    }
                 } catch (CartItemModifyException e) {
                     Debug.logError(e, "Problem exploding item! Item not 
exploded.", module);
                 }
@@ -3563,7 +3573,17 @@ public class ShoppingCart implements Ite
             for (ShoppingCartItem item : shoppingCartItems) {
                 //Debug.logInfo("Item qty: " + item.getQuantity(), module);
                 try {
-                    item.explodeItem(this, dispatcher);
+                    int thisIndex = items().indexOf(item);
+                    List<ShoppingCartItem> explodedItems = 
item.explodeItem(this, dispatcher);
+
+                    // Add exploded items into cart with order item sequence 
id and item ship group quantity
+                    for (ShoppingCartItem explodedItem : explodedItems) {
+                        String orderItemSeqId = 
UtilFormatOut.formatPaddedNumber(nextItemSeq, 5);
+                        explodedItem.setOrderItemSeqId(orderItemSeqId);
+                        addItemToEnd(explodedItem);
+                        setItemShipGroupQty(explodedItem, BigDecimal.ONE, 
thisIndex);
+                        nextItemSeq++;
+                    }
                 } catch (CartItemModifyException e) {
                     Debug.logError(e, "Problem exploding (unitizing) item! 
Item not exploded.", module);
                 }

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?rev=1646977&r1=1646976&r2=1646977&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
 Sat Dec 20 13:38:06 2014
@@ -2511,7 +2511,7 @@ public class ShoppingCartItem implements
         return delegator;
     }
 
-    public void explodeItem(ShoppingCart cart, LocalDispatcher dispatcher) 
throws CartItemModifyException {
+    public List<ShoppingCartItem> explodeItem(ShoppingCart cart, 
LocalDispatcher dispatcher) throws CartItemModifyException {
         BigDecimal baseQuantity = this.getQuantity();
         int thisIndex = cart.items().indexOf(this);
         List<ShoppingCartItem> newItems = new ArrayList<ShoppingCartItem>();
@@ -2523,7 +2523,6 @@ public class ShoppingCartItem implements
 
                 // set the new item's quantity
                 item.setQuantity(BigDecimal.ONE, dispatcher, cart, false);
-
                 // now copy/calc the adjustments
                 Debug.logInfo("Clone's adj: " + item.getAdjustments(), module);
                 if (UtilValidate.isNotEmpty(item.getAdjustments())) {
@@ -2573,11 +2572,8 @@ public class ShoppingCartItem implements
                 }
             }
 
-            // add the cloned item(s) to the cart
-            for (ShoppingCartItem sci : newItems) {
-                cart.addItem(thisIndex, sci);
-            }
         }
+        return newItems;
     }
 
     public static String getPurchaseOrderItemDescription(GenericValue product, 
GenericValue supplierProduct, Locale locale) {


Reply via email to