Author: jaz
Date: Wed Mar 28 12:17:29 2007 New Revision: 523440 URL: http://svn.apache.org/viewvc?view=rev&rev=523440 Log: new service to wrap creating an order form a shopping cart Modified: ofbiz/trunk/applications/order/servicedef/services.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Modified: ofbiz/trunk/applications/order/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=523440&r1=523439&r2=523440 ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services.xml Wed Mar 28 12:17:29 2007 @@ -142,11 +142,15 @@ </service> <service name="callProcessOrderPayments" engine="java" - location="org.ofbiz.order.order.OrderServices" invoke="callProcessOrderPayments" auth="true"> + location="org.ofbiz.order.order.OrderServices" invoke="callProcessOrderPayments" auth="false"> <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/> <attribute name="manualHold" type="Boolean" mode="IN" optional="true"/> </service> - + <service name="createOrderFromShoppingCart" engine="java" + location="org.ofbiz.order.order.OrderServices" invoke="createOrderFromShoppingCart" auth="false"> + <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="INOUT" optional="false"/> + <attribute name="orderId" type="String" mode="OUT" optional="false"/> + </service> <service name="createSimpleNonProductSalesOrder" engine="java" location="org.ofbiz.order.order.OrderServices" invoke="createSimpleNonProductSalesOrder" auth="true"> <attribute name="paymentMethodId" type="String" mode="IN" optional="false"/> 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?view=diff&rev=523440&r1=523439&r2=523440 ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Wed Mar 28 12:17:29 2007 @@ -4016,6 +4016,12 @@ Map itemMap = (Map) context.get("itemMap"); ShoppingCart cart = new ShoppingCart(delegator, productStoreId, null, locale, currency); + try { + cart.setUserLogin(userLogin, dispatcher); + } catch (CartItemModifyException e) { + Debug.logError(e, module); + return ServiceUtil.returnError(e.getMessage()); + } cart.setOrderType("SALES_ORDER"); cart.setOrderPartyId(partyId); @@ -4061,13 +4067,34 @@ return result; } + // generic method for creating an order from a shopping cart + public static Map createOrderFromShoppingCart(DispatchContext dctx, Map context) { + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericDelegator delegator = dctx.getDelegator(); + + ShoppingCart cart = (ShoppingCart) context.get("shoppingCart"); + GenericValue userLogin = cart.getUserLogin(); + + CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart); + Map createOrder = coh.createOrder(userLogin); + if (ServiceUtil.isError(createOrder)) { + return createOrder; + } + String orderId = (String) createOrder.get("orderId"); + + Map result = ServiceUtil.returnSuccess(); + result.put("shoppingCart", cart); + result.put("orderId", orderId); + return result; + } + // generic method for processing an order's payment(s) public static Map callProcessOrderPayments(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); - GenericValue userLogin = (GenericValue) context.get("userLogin"); ShoppingCart cart = (ShoppingCart) context.get("shoppingCart"); + GenericValue userLogin = cart.getUserLogin(); Boolean manualHold = (Boolean) context.get("manualHold"); if (manualHold == null) { manualHold = Boolean.FALSE; |
Free forum by Nabble | Edit this page |