Wednesday, July 4, 2012

Creating Orders : ATG


Creating An Order:


The first step in working with Commerce objects is to create an Order. A shopping cart is an implementation of the Order interface. To create an Order, you must have a reference to an OrderManager or SimpleOrderManager. Once you have the reference, use createOrder() to create the new Order.

There are many versions of the createOrder method, each of which takes a different set of parameters:

createOrder(String pProfileId)


createOrder(String pProfileId, String pOrderType)


createOrder(String pProfileId, String pOrderId, String pOrderType)


createOrder(String pProfileId, OrderPriceInfo pOrderPriceInfo, TaxPriceInfo pTaxPriceInfo, ShippingPriceInfo pShippingPriceInfo)


createOrder(String pProfileId, OrderPriceInfo pOrderPriceInfo, TaxPriceInfo pTaxPriceInfo, ShippingPriceInfo pShippingPriceInfo, String pOrderType)


createOrder(String pProfileId, String pOrderId, OrderPriceInfo pOrderPriceInfo, TaxPriceInfo pTaxPriceInfo, ShippingPriceInfo pShippingPriceInfo, String pOrderType)

All methods create an Order object and assign it a unique ID. The type of Order created depends on the method used. If the method takes an orderType parameter, that parameter determines the type of object that is constructed. Otherwise, the defaultOrderType property of the OrderTools component defines the Order type.

By default, an Order contains one empty ShippingGroup and one empty PaymentGroup when it is created, and their types are determined by the defaultShippingGroupType and defaultPaymentGroupType properties of the OrderTools component.

Note: If you do not want to create an empty ShippingGroup and an empty PaymentGroup for every new Order, set the createDefaultShippingGroup and createDefaultPaymentGroup properties in the OrderTools component to false.

The following example demonstrates how to create an Order:

// Get a reference to the OrderManager
OrderManager orderManager = (OrderManager)
  request.resolveName("/atg/commerce/order/OrderManager");


// Create the Order
Order order = orderManager.createOrder(profileId);


By default, orders are persistent. To disable persistence, set the persistOrders property in the ShoppingCart component to false. The ShoppingCart component is located in Nucleus at /atg/commerce/.


Creating Multiple Orders


Customers can have an unlimited number of orders in existence at one time. They can place items in different shopping carts, switch between carts, retrieve a list of saved carts, delete carts, and can check out one cart’s contents while waiting until later to check out the contents of others.

Using multiple orders requires atg.commerce.order.OrderHolder in addition to atg.commerce.order.Order. This class maintains the current Order object as well as a collection of saved Order objects. The component that utilizes OrderHolder is /atg/commerce/ShoppingCart, a session-scoped component whose handleXXX methods add, delete, and switch between carts, as explained in the rest of this section.

You implement multiple shopping carts using the handleCreate method of the OrderHolder class. This method creates a new Order and sets it as the currentOrder in the OrderHolder. Any previously existing Order object is placed into the collection of saved carts. Refer to the following JSP example:

<dsp:form action="ShoppingCart.jsp" method="post">
  <dsp:input bean="ShoppingCart.create" value="Create" type="submit"/> another
   shopping cart.<BR>
</dsp:form>

The handleSwitch() method allows customers to switch between shopping carts. It switches the current Order object out to the saved collection of orders and sets the current Order to the Order identified by the handlerOrderId property. For example, if a customer has several shopping carts saved, you can allow them to switch between any of the Order objects using the following JSP code:

<dsp:form action="ShoppingCart.jsp" method="post">
 <dsp:select bean="ShoppingCart.handlerOrderId">
  <dsp:droplet name="ForEach">
   <dsp:param bean="ShoppingCart.saved" name="array"/>
   <dsp:param value="SavedOrder" name="elementName"/>
   <dsp:oparam name="output">
    <dsp:getvalueof id="option12" param="SavedOrder.id" idtype="java.lang.String">
<dsp:option value="<%=option12%>"/>
</dsp:getvalueof>
     <valueofparam="SavedOrder.id"></dsp:valueof>
    </dsp:oparam>
   </dsp:droplet>
 </dsp:select>
 <dsp:input bean="ShoppingCart.switch" value="Switch" type="submit"/>
</dsp:form>


The example iterates through the list of saved shopping carts, displays the shopping carts to the customer, and gives the customer the option to select one of the saved carts. The handlerOrderId property would be set to the selected Order ID, and the corresponding Order would be set as the current Order.

The handleDelete() and handleDeleteAll() methods remove a single Order or all orders (both current and saved), respectively.

1 comment:

Unknown said...

simply copy pasting from dac yr, need more explanation.

Popular Posts