Tuesday, August 14, 2012

Creating and Retrieving Shopping Carts : ATG


As previously mentioned in this chapter, the ShoppingCart component stores a user’s current and saved shopping carts. You can use the ShoppingCart component’s properties and handle methods to create a new shopping cart or retrieve one of the user’s saved shopping carts and make it the user’s current shopping cart.


The following JSP example illustrates how to create and retrieve shopping carts. In the example, the ShoppingCart.savedEmpty property is checked to determine whether the current user has any saved shopping carts. If the user doesn’t have any saved shopping carts, the user is given the option to create one. If the user has saved shopping carts, the user is given the option to select one of the saved shopping carts to either delete or make the current shopping cart, to delete all of the saved shopping carts, or to create a new shopping cart.


<dsp:importbean bean="/atg/commerce/ShoppingCart"/>

<dsp:form action="shoppingcart.jsp" method="post">

 <dsp:droplet name="/atg/dynamo/droplet/Switch">
   <dsp:param bean="ShoppingCart.savedEmpty" name="value"/>

   <dsp:oparam name="true">
     <!-- since there are no saved carts, we cannot switch to another so
          we only give them the option to create a new cart -->
     <dsp:input bean="ShoppingCart.create" value="Create" type="submit"/>
another shopping cart
   </dsp:oparam>

   <dsp:oparam name="false">
     <!-- We have other shopping carts, so let them do everything -->
     Shopping Cart <dsp:select bean="ShoppingCart.handlerOrderId">
     <dsp:droplet name="ForEach">
       <dsp:param bean="ShoppingCart.saved" name="array"/>
       <dsp:param value="savedcart" name="elementName"/>
       <dsp:oparam name="output">
         <dsp:getvalueof id="option26" param="savedcart.id"
idtype="java.lang.String">
<dsp:option value="<%=option26%>"/>
</dsp:getvalueof><dsp:valueof param="savedcart.id"/>
       </dsp:oparam>
     </dsp:droplet>
     </dsp:select>:
  <dsp:input bean="ShoppingCart.switch" value="Switch" type="submit"/> to,
  <dsp:input bean="ShoppingCart.delete" value="Delete" type="submit"/> or
  <dsp:input bean="ShoppingCart.create" value="Create" type="submit"/>
       another shopping cart.<BR>
     <dsp:input bean="ShoppingCart.deleteAll"
value="Delete All Shopping Carts" type="submit"/>
   </dsp:oparam>

 </dsp:droplet>

</dsp:form>

No comments:

Popular Posts