svn commit: r601255 - in /ofbiz/trunk/applications/order: servicedef/services_cart.xml src/org/ofbiz/order/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: r601255 - in /ofbiz/trunk/applications/order: servicedef/services_cart.xml src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java

apatel-2
Author: apatel
Date: Wed Dec  5 00:49:11 2007
New Revision: 601255

URL: http://svn.apache.org/viewvc?rev=601255&view=rev
Log:
missed few files from previous commit.

Modified:
    ofbiz/trunk/applications/order/servicedef/services_cart.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java

Modified: ofbiz/trunk/applications/order/servicedef/services_cart.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_cart.xml?rev=601255&r1=601254&r2=601255&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_cart.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_cart.xml Wed Dec  5 00:49:11 2007
@@ -141,4 +141,16 @@
         <attribute name="productId" type="String" mode="IN" optional="false"/>
  <attribute name="itemIndex" type="String" mode="OUT" optional="true"/>
     </service>
+
+    <service name="resetShipGroupItems" engine="java" auth="false"
+            location="org.ofbiz.order.shoppingcart.ShoppingCartServices" invoke="resetShipGroupItems">
+        <description>Reset the ship Groups in the cart and put the items in default group</description>
+        <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
+    </service>
+    
+    <service name="prepareVendorShipGroups" engine="java" auth="false"
+            location="org.ofbiz.order.shoppingcart.ShoppingCartServices" invoke="prepareVendorShipGroups">
+        <description>Split the default shipgroup to individual shipgroups that are unique to a vendor</description>
+        <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
+    </service>
 </services>

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=601255&r1=601254&r2=601255&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 Wed Dec  5 00:49:11 2007
@@ -30,6 +30,7 @@
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilFormatOut;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
@@ -41,8 +42,10 @@
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.order.order.OrderReadHelper;
 import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ServiceUtil;
 
@@ -833,6 +836,81 @@
                 result.put("itemIndex", String.valueOf(itemIndex));
             }
         }
+        return result;
+    }
+    
+    public static Map resetShipGroupItems(DispatchContext dctx, Map context) {
+        Map result = ServiceUtil.returnSuccess();
+        ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");
+        Iterator sciIter = cart.iterator();
+        while (sciIter.hasNext()) {
+            ShoppingCartItem item = (ShoppingCartItem) sciIter.next();
+            cart.clearItemShipInfo(item);
+            cart.setItemShipGroupQty(item, item.getQuantity(), 0);
+        }
+        return result;
+    }
+    
+    public static Map prepareVendorShipGroups(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+        ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");
+        Map result = ServiceUtil.returnSuccess();
+        try {
+            Map resp = dispatcher.runSync("resetShipGroupItems", context);
+            if (ServiceUtil.isError(resp)) {
+                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(resp));
+            }
+        } catch (GenericServiceException e) {
+            Debug.logError(e.toString(), module);
+            return ServiceUtil.returnError(e.toString());
+        }
+        Map vendorMap = FastMap.newInstance();
+        Iterator sciIter = cart.iterator();
+        while (sciIter.hasNext()) {
+            ShoppingCartItem item = (ShoppingCartItem) sciIter.next();
+            GenericValue vendorProduct = null;
+            String productId = item.getParentProductId();
+            if (productId == null) {
+                productId = item.getProductId();
+            }
+            int index = 0;
+            try {
+                vendorProduct = EntityUtil.getFirst(delegator.findByAnd("VendorProduct", UtilMisc.toMap("productId", productId, "productStoreGroupId", "_NA_")));
+            } catch (GenericEntityException e) {
+                Debug.logError(e.toString(), module);
+            }
+            
+            if (UtilValidate.isEmpty(vendorProduct)) {
+                if (vendorMap.containsKey("_NA_")) {
+                    index = ((Integer) vendorMap.get("_NA_")).intValue();
+                    cart.positionItemToGroup(item, item.getQuantity(), 0, index, true);
+                } else {
+                    index = cart.addShipInfo();
+                    vendorMap.put("_NA_", index);
+                    
+                    ShoppingCart.CartShipInfo info = cart.getShipInfo(index);
+                    info.setVendorPartyId("_NA_");
+                    info.setShipGroupSeqId(UtilFormatOut.formatPaddedNumber(index, 5));
+                    cart.positionItemToGroup(item, item.getQuantity(), 0, index, true);
+                }
+            }
+            if (UtilValidate.isNotEmpty(vendorProduct)) {
+                String vendorPartyId = vendorProduct.getString("vendorPartyId");
+                if (vendorMap.containsKey(vendorPartyId)) {
+                    index = ((Integer) vendorMap.get(vendorPartyId)).intValue();
+                    cart.positionItemToGroup(item, item.getQuantity(), 0, index, true);
+                } else {
+                    index = cart.addShipInfo();
+                    vendorMap.put(vendorPartyId, index);
+                    
+                    ShoppingCart.CartShipInfo info = cart.getShipInfo(index);
+                    info.setVendorPartyId(vendorPartyId);
+                    info.setShipGroupSeqId(UtilFormatOut.formatPaddedNumber(index, 5));
+                    cart.positionItemToGroup(item, item.getQuantity(), 0, index, true);
+                }
+            }
+        }        
         return result;
     }
 }