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

apatel-2
Author: apatel
Date: Tue Aug 14 01:05:12 2007
New Revision: 565651

URL: http://svn.apache.org/viewvc?view=rev&rev=565651
Log:
adding service to return shoppingCart data.

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?view=diff&rev=565651&r1=565650&r2=565651
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_cart.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_cart.xml Tue Aug 14 01:05:12 2007
@@ -116,4 +116,17 @@
         <attribute name="applyStorePromotions" type="String" mode="IN" optional="true"/>
         <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/>
     </service>
+
+    <service name="getShoppingCartData" engine="java" auth="false"
+            location="org.ofbiz.order.shoppingcart.ShoppingCartServices" invoke="getShoppingCartData">
+        <description>Get the ShoppingCart data</description>
+        <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
+        <attribute name="totalQuantity" type="Double" mode="OUT" optional="true"/>
+        <attribute name="currencyIsoCode" type="String" mode="OUT" optional="true"/>
+        <attribute name="subTotal" type="Double" mode="OUT" optional="true"/>
+        <attribute name="totalShipping" type="Double" mode="OUT" optional="true"/>
+        <attribute name="totalSalesTax" type="Double" mode="OUT" optional="true"/>
+        <attribute name="displayGrandTotal" type="Double" mode="OUT" optional="true"/>
+        <attribute name="cartItemData" type="Map" mode="OUT"/>
+    </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?view=diff&rev=565651&r1=565650&r2=565651
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java Tue Aug 14 01:05:12 2007
@@ -26,6 +26,8 @@
 import java.util.HashMap;
 import java.util.LinkedList;
 
+import javolution.util.FastMap;
+
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
@@ -751,6 +753,29 @@
 
         Map result = ServiceUtil.returnSuccess();
         result.put("shoppingCart", cart);
+        return result;
+    }
+    
+    public static Map getShoppingCartData(DispatchContext dctx, Map context){
+        Map result = ServiceUtil.returnSuccess();
+        ShoppingCart shoppingCart = (ShoppingCart) context.get("shoppingCart");
+        if(shoppingCart != null){
+            result.put("totalQuantity",new Double(shoppingCart.getTotalQuantity()));
+            result.put("currencyIsoCode",shoppingCart.getCurrency());
+            result.put("subTotal",new Double(shoppingCart.getSubTotal()));
+            result.put("totalShipping",new Double(shoppingCart.getTotalShipping()));
+            result.put("totalSalesTax",new Double(shoppingCart.getTotalSalesTax()));
+            result.put("displayGrandTotal",new Double(shoppingCart.getDisplayGrandTotal()));
+
+            Iterator i = shoppingCart.iterator();
+            Map cartItemData = FastMap.newInstance();
+            while (i.hasNext()) {
+                ShoppingCartItem cartLine = (ShoppingCartItem) i.next();
+                int cartLineIndex = shoppingCart.getItemIndex(cartLine);
+                cartItemData.put("displayItemSubTotal_" + cartLineIndex ,new Double(cartLine.getDisplayItemSubTotal()));
+            }
+            result.put("cartItemData",cartItemData);
+        }
         return result;
     }
 }