svn commit: r896855 - in /ofbiz/trunk/applications/order/src/org/ofbiz/order: order/OrderServices.java shoppingcart/ShoppingCart.java shoppingcart/ShoppingCartItem.java shoppingcart/ShoppingCartServices.java

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

svn commit: r896855 - in /ofbiz/trunk/applications/order/src/org/ofbiz/order: order/OrderServices.java shoppingcart/ShoppingCart.java shoppingcart/ShoppingCartItem.java shoppingcart/ShoppingCartServices.java

jonesde
Author: jonesde
Date: Thu Jan  7 11:59:48 2010
New Revision: 896855

URL: http://svn.apache.org/viewvc?rev=896855&view=rev
Log:
Fixed some issues where code was destroying OrderItemShipGroup information, especially when loading an existing order; improved addOrderItem service to better support purchase order item adding

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

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=896855&r1=896854&r2=896855&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 Thu Jan  7 11:59:48 2010
@@ -3314,20 +3314,37 @@
 
         // add in the new product
         try {
-            ShoppingCartItem item = ShoppingCartItem.makeItem(null, productId, null, quantity, null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, null, null, null, Boolean.FALSE, Boolean.FALSE);
-            if (basePrice != null && overridePrice != null) {
-                item.setBasePrice(basePrice);
-                // special hack to make sure we re-calc the promos after a price change
-                item.setQuantity(quantity.add(BigDecimal.ONE), dispatcher, cart, false);
-                item.setQuantity(quantity, dispatcher, cart, false);
-                item.setBasePrice(basePrice);
-                item.setIsModifiedPrice(true);
-            }
-
+            if ("PURCHASE_ORDER".equals(cart.getOrderType())) {
+                GenericValue supplierProduct = cart.getSupplierProduct(productId, quantity, dispatcher);
+                ShoppingCartItem item = null;
+                if (supplierProduct != null) {
+                    item = ShoppingCartItem.makePurchaseOrderItem(null, productId, null, quantity, null, null, prodCatalogId, null, null, null, dispatcher, cart, supplierProduct, itemDesiredDeliveryDate, itemDesiredDeliveryDate, null);
+                    cart.addItem(0, item);
+                } else {
+                    throw new CartItemModifyException("No supplier information found for product [" + productId + "] and quantity quantity [" + quantity + "], cannot add to cart.");
+                }
+                
+                if (basePrice != null) {
+                    item.setBasePrice(basePrice);
+                    item.setIsModifiedPrice(true);
+                }
+                
+                cart.setItemShipGroupQty(item, item.getQuantity(), shipGroupIdx);
+            } else {
+                ShoppingCartItem item = ShoppingCartItem.makeItem(null, productId, null, quantity, null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, null, null, null, Boolean.FALSE, Boolean.FALSE);
+                if (basePrice != null && overridePrice != null) {
+                    item.setBasePrice(basePrice);
+                    // special hack to make sure we re-calc the promos after a price change
+                    item.setQuantity(quantity.add(BigDecimal.ONE), dispatcher, cart, false);
+                    item.setQuantity(quantity, dispatcher, cart, false);
+                    item.setBasePrice(basePrice);
+                    item.setIsModifiedPrice(true);
+                }
 
-            // set the item in the selected ship group
-            item.setShipBeforeDate(itemDesiredDeliveryDate);
-            cart.setItemShipGroupQty(item, item.getQuantity(), shipGroupIdx);
+                // set the item in the selected ship group
+                item.setShipBeforeDate(itemDesiredDeliveryDate);
+                cart.setItemShipGroupQty(item, item.getQuantity(), shipGroupIdx);
+            }
         } catch (CartItemModifyException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError(e.getMessage());

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=896855&r1=896854&r2=896855&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 Thu Jan  7 11:59:48 2010
@@ -433,7 +433,7 @@
         return this.cartCreatedTs;
     }
 
-    private GenericValue getSupplierProduct(String productId, BigDecimal quantity, LocalDispatcher dispatcher) {
+    public GenericValue getSupplierProduct(String productId, BigDecimal quantity, LocalDispatcher dispatcher) {
         GenericValue supplierProduct = null;
         Map params = UtilMisc.toMap("productId", productId,
                                     "partyId", this.getPartyId(),
@@ -1977,7 +1977,9 @@
             CartShipInfo csi = this.getShipInfo(i);
             csi.shipItemInfo.remove(item);
         }
-        this.cleanUpShipGroups();
+        
+        // DEJ20100107: commenting this out because we do NOT want to clear out ship group info since there is information there that will be lost; good enough to clear the item/group association which can be restored later (though questionable, the whole processes using this should be rewritten to not destroy information!
+        // this.cleanUpShipGroups();
     }
 
     public void setItemShipGroupEstimate(BigDecimal amount, int idx) {
@@ -2115,6 +2117,7 @@
     }
 
     public void cleanUpShipGroups() {
+        Debug.logInfo(new Exception(), "==================== Call of cleanUpShipGroups!", module);
         for (CartShipInfo csi : this.shipInfo) {
             Iterator<ShoppingCartItem> si = csi.shipItemInfo.keySet().iterator();
             while (si.hasNext()) {
@@ -2245,7 +2248,7 @@
     public void setMaySplit(int idx, Boolean maySplit) {
         CartShipInfo csi = this.getShipInfo(idx);
         if (UtilValidate.isNotEmpty(maySplit)) {
-            csi.maySplit = maySplit.booleanValue() ? "Y" : "N";
+            csi.setMaySplit(maySplit);
         }
     }
 
@@ -4294,7 +4297,7 @@
         public String supplierPartyId = null;
         public String carrierRoleTypeId = null;
         public String carrierPartyId = null;
-        public String facilityId = null;
+        private String facilityId = null;
         public String giftMessage = null;
         public String shippingInstructions = null;
         public String maySplit = "N";
@@ -4302,28 +4305,49 @@
         public BigDecimal shipEstimate = BigDecimal.ZERO;
         public Timestamp shipBeforeDate = null;
         public Timestamp shipAfterDate = null;
-        public String shipGroupSeqId = null;
+        private String shipGroupSeqId = null;
         public String vendorPartyId = null;
+        
+        public CartShipInfo() {
+            // Debug.logInfo(new Exception(), "Created a new CartShipInfo", module);
+        }
 
         public String getOrderTypeId() { return orderTypeId; }
+        
         public String getContactMechId() { return internalContactMechId; }
         public void setContactMechId(String contactMechId) {
             this.internalContactMechId = contactMechId;
             // Debug.logInfo(new Exception(), "Set CartShipInfo.contactMechId=" + this.internalContactMechId, module);
         }
+        
         public String getCarrierPartyId() { return carrierPartyId; }
         public String getSupplierPartyId() { return supplierPartyId; }
         public String getShipmentMethodTypeId() { return shipmentMethodTypeId; }
         public BigDecimal getShipEstimate() { return shipEstimate; }
+
         public String getShipGroupSeqId() { return shipGroupSeqId; }
-        public String getFacilityId() { return facilityId; }
         public void setShipGroupSeqId(String shipGroupSeqId) {
             this.shipGroupSeqId = shipGroupSeqId;
+            // Debug.logInfo(new Exception(), "============= On CartShipInfo shipGroupSeqId to " + this.shipGroupSeqId, module);
+        }
+        
+        public String getFacilityId() { return facilityId; }
+        public void setFacilityId(String facilityId) {
+            this.facilityId = facilityId;
+            // Debug.logInfo(new Exception(), "============= On CartShipInfo setFacilityId to " + this.facilityId, module);
         }
+        
         public String getVendorPartyId() { return vendorPartyId;}
         public void setVendorPartyId(String vendorPartyId) {
             this.vendorPartyId = vendorPartyId;
         }
+        
+        public void setMaySplit(Boolean maySplit) {
+            if (UtilValidate.isNotEmpty(maySplit)) {
+                this.maySplit = maySplit.booleanValue() ? "Y" : "N";
+            }
+        }
+        
 
         public List makeItemShipGroupAndAssoc(Delegator delegator, ShoppingCart cart, long groupIndex) {
             shipGroupSeqId = UtilFormatOut.formatPaddedNumber(groupIndex, 5);
@@ -4351,6 +4375,8 @@
             shipGroup.set("shipGroupSeqId", shipGroupSeqId);
             shipGroup.set("vendorPartyId", vendorPartyId);
             shipGroup.set("facilityId", facilityId);
+            
+            // Debug.logInfo("=================Creating ship group value: " + shipGroup, module);
 
             // use the cart's default ship before and after dates here
             if ((shipBeforeDate == null) && (cart.getDefaultShipBeforeDate() != null)) {

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=896855&r1=896854&r2=896855&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 Thu Jan  7 11:59:48 2010
@@ -239,7 +239,7 @@
         newItem.setCancelBackOrderDate(cancelBackOrderDate != null ? cancelBackOrderDate : cart.getCancelBackOrderDate());
 
         try {
-            newItem.setQuantity(quantity, dispatcher, cart, true);
+            newItem.setQuantity(quantity, dispatcher, cart, true, false);
         } catch (CartItemModifyException e) {
             cart.removeCartItem(cart.getItemIndex(newItem), dispatcher);
             cart.clearItemShipInfo(newItem);

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java?rev=896855&r1=896854&r2=896855&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java Thu Jan  7 11:59:48 2010
@@ -44,6 +44,7 @@
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.order.order.OrderReadHelper;
+import org.ofbiz.order.shoppingcart.ShoppingCart.CartShipInfo;
 import org.ofbiz.product.config.ProductConfigWorker;
 import org.ofbiz.product.config.ProductConfigWrapper;
 import org.ofbiz.service.DispatchContext;
@@ -298,6 +299,40 @@
             Debug.log("No payment preferences found for order #" + orderId, module);
         }
 
+        List<GenericValue> orderItemShipGroupList = orh.getOrderItemShipGroups();
+        for (GenericValue orderItemShipGroup: orderItemShipGroupList) {
+            // Debug.logInfo("===================== Load order: orderItemShipGroup=" + orderItemShipGroup, module);
+            
+            // should be sorted by shipGroupSeqId
+            int newShipInfoIndex = cart.addShipInfo();
+            
+            // shouldn't be gaps in it but allow for that just in case
+            String cartShipGroupIndexStr = orderItemShipGroup.getString("shipGroupSeqId");
+            int cartShipGroupIndex = NumberUtils.toInt(cartShipGroupIndexStr);
+            
+            if (newShipInfoIndex != (cartShipGroupIndex - 1)) {
+                int groupDiff = cartShipGroupIndex - cart.getShipGroupSize();
+                for (int i = 0; i < groupDiff; i++) {
+                    newShipInfoIndex = cart.addShipInfo();
+                }
+            }
+            
+            CartShipInfo cartShipInfo = cart.getShipInfo(newShipInfoIndex);
+            
+            cartShipInfo.shipAfterDate = orderItemShipGroup.getTimestamp("shipAfterDate");
+            cartShipInfo.shipBeforeDate = orderItemShipGroup.getTimestamp("shipByDate");
+            cartShipInfo.shipmentMethodTypeId = orderItemShipGroup.getString("shipmentMethodTypeId");
+            cartShipInfo.carrierPartyId = orderItemShipGroup.getString("carrierPartyId");
+            cartShipInfo.supplierPartyId = orderItemShipGroup.getString("supplierPartyId");
+            cartShipInfo.setMaySplit(orderItemShipGroup.getBoolean("maySplit"));
+            cartShipInfo.giftMessage = orderItemShipGroup.getString("giftMessage");
+            cartShipInfo.setContactMechId(orderItemShipGroup.getString("contactMechId"));
+            cartShipInfo.shippingInstructions = orderItemShipGroup.getString("shippingInstructions");
+            cartShipInfo.setFacilityId(orderItemShipGroup.getString("facilityId"));
+            cartShipInfo.setVendorPartyId(orderItemShipGroup.getString("vendorPartyId"));
+            cartShipInfo.setShipGroupSeqId(orderItemShipGroup.getString("shipGroupSeqId"));
+        }
+
         List<GenericValue> orderItems = orh.getValidOrderItems();
         long nextItemSeq = 0;
         if (UtilValidate.isNotEmpty(orderItems)) {
@@ -499,54 +534,29 @@
                     }
                 }
             }
-
+            
+            // setup the OrderItemShipGroupAssoc records
             if (UtilValidate.isNotEmpty(orderItems)) {
                 int itemIndex = 0;
                 for (GenericValue item : orderItems) {
 
                     // set the item's ship group info
-                    List<GenericValue> shipGroups = orh.getOrderItemShipGroupAssocs(item);
-                    for (int g = 0; g < shipGroups.size(); g++) {
-                        GenericValue sgAssoc = (GenericValue) shipGroups.get(g);
+                    List<GenericValue> shipGroupAssocs = orh.getOrderItemShipGroupAssocs(item);
+                    for (int g = 0; g < shipGroupAssocs.size(); g++) {
+                        GenericValue sgAssoc = (GenericValue) shipGroupAssocs.get(g);
                         BigDecimal shipGroupQty = OrderReadHelper.getOrderItemShipGroupQuantity(sgAssoc);
                         if (shipGroupQty == null) {
                             shipGroupQty = BigDecimal.ZERO;
                         }
-
-                        GenericValue sg = null;
-                        try {
-                            sg = sgAssoc.getRelatedOne("OrderItemShipGroup");
-                        } catch (GenericEntityException e) {
-                            Debug.logError(e, module);
-                            return ServiceUtil.returnError(e.getMessage());
-                        }
-                        String cartShipGroupIndexStr = sg.getString("shipGroupSeqId");
+                        
+                        String cartShipGroupIndexStr = sgAssoc.getString("shipGroupSeqId");
                         int cartShipGroupIndex = NumberUtils.toInt(cartShipGroupIndexStr);
 
-                        if (cart.getShipGroupSize() < cartShipGroupIndex) {
-                            int groupDiff = cartShipGroupIndex - cart.getShipGroupSize();
-                            for (int i = 0; i < groupDiff; i++) {
-                                cart.addShipInfo();
-                            }
-                        }
-
                         cartShipGroupIndex = cartShipGroupIndex - 1;
                         if (cartShipGroupIndex > 0) {
                             cart.positionItemToGroup(itemIndex, shipGroupQty, 0, cartShipGroupIndex, false);
                         }
-
-                        cart.setShipAfterDate(cartShipGroupIndex, sg.getTimestamp("shipAfterDate"));
-                        cart.setShipBeforeDate(cartShipGroupIndex, sg.getTimestamp("shipByDate"));
-                        cart.setShipmentMethodTypeId(cartShipGroupIndex, sg.getString("shipmentMethodTypeId"));
-                        cart.setCarrierPartyId(cartShipGroupIndex, sg.getString("carrierPartyId"));
-                        cart.setSupplierPartyId(cartShipGroupIndex, sg.getString("supplierPartyId"));
-                        cart.setMaySplit(cartShipGroupIndex, sg.getBoolean("maySplit"));
-                        cart.setGiftMessage(cartShipGroupIndex, sg.getString("giftMessage"));
-                        cart.setShippingContactMechId(cartShipGroupIndex, sg.getString("contactMechId"));
-                        cart.setShippingInstructions(cartShipGroupIndex, sg.getString("shippingInstructions"));
-                        cart.setShipGroupFacilityId(cartShipGroupIndex, sg.getString("facilityId"));
-                        cart.setShipGroupVendorPartyId(cartShipGroupIndex, sg.getString("vendorPartyId"));
-                        cart.setShipGroupSeqId(cartShipGroupIndex, sg.getString("shipGroupSeqId"));
+                        
                         cart.setItemShipGroupQty(itemIndex, shipGroupQty, cartShipGroupIndex);
                     }
                     itemIndex ++;