Author: ruppert
Date: Sun Aug 19 16:21:20 2007
New Revision: 567507
URL:
http://svn.apache.org/viewvc?rev=567507&view=revLog:
Added service to get the cart-based index of the first cart item for a particular productId
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=567507&r1=567506&r2=567507&view=diff==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_cart.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_cart.xml Sun Aug 19 16:21:20 2007
@@ -133,4 +133,12 @@
<attribute name="displayGrandTotalCurrencyFormatted" type="String" mode="OUT" optional="true"/>
<attribute name="cartItemData" type="Map" mode="OUT"/>
</service>
+
+ <service name="getShoppingCartItemIndex" engine="java" auth="false"
+ location="org.ofbiz.order.shoppingcart.ShoppingCartServices" invoke="getShoppingCartItemIndex">
+ <description>Get the ShoppingCart info from the productId</description>
+ <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
+ <attribute name="productId" type="String" mode="IN" optional="false"/>
+ <attribute name="itemIndex" type="String" mode="OUT" optional="true"/>
+ </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=567507&r1=567506&r2=567507&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 Sun Aug 19 16:21:20 2007
@@ -816,4 +816,21 @@
}
return result;
}
+
+ public static Map getShoppingCartItemIndex(DispatchContext dctx, Map context){
+ Map result = ServiceUtil.returnSuccess();
+ Locale locale = (Locale) context.get("locale");
+ ShoppingCart shoppingCart = (ShoppingCart) context.get("shoppingCart");
+ String productId = (String) context.get("productId");
+ if (shoppingCart != null && shoppingCart.items() > 0){
+ List allItems = shoppingCart.items();
+ List items = shoppingCart.findAllCartItems(productId);
+ if (items.size() > 0) {
+ ShoppingCartItem item = (ShoppingCartItem)items.get(0);
+ int itemIndex = shoppingCart.getItemIndex(item);
+ result.put("itemIndex", String.valueOf(itemIndex));
+ }
+ }
+ return result;
+ }
}