Sunday, 28 February 2016

sample Code for Add single Item to Cart and multiple Items to cart in ATG



Adding Single Item to cart (Simple Way):

<dsp:form method="post">
 <input type="hidden" name="group" value="${group}"/>
 <dsp:input type="hidden" paramvalue="sku.id" bean="CartModifierFormHandler.catalogRefIds"></dsp:input>
 <dsp:input  type="text" value="${Product.id}" bean="CartModifierFormHandler.productId"></dsp:input>
 <dsp:input  type="hidden" value="${MySite}" bean="CartModifierFormHandler.siteId"></dsp:input>
 Quantity:<dsp:input  type="text" value="1" size="4" bean="CartModifierFormHandler.quantity"></dsp:input>
 <dsp:input type="hidden" value="cart.jsp" bean="CartModifierFormHandler.addItemToOrderSuccessURL"></dsp:input> 
 <dsp:input type="hidden" value="productDetailsPage.jsp" bean="CartModifierFormHandler.addItemToOrderErrorURL"></dsp:input>
 <dsp:input type="submit" bean="CartModifierFormHandler.addItemToOrder" value="Add Item TO Cart"></dsp:input> 
</dsp:form>


Adding Single item to cart (using Items property of cart form handler) :

<c:set var="successParams">/walletshop/productDisplay.jsp?categoryId=<dsp:valueof param="categoryId"/></c:set>
<dsp:form id="addSku" action="/walletshop/productDisplay.jsp">
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.addItemCount" value="1" type="hidden"/>
 <dspel:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.addItemToOrderSuccessURL" value="${successParams}" type="hidden"/>
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.addItemToOrderErrorURL" value="/walletshop/errors.jsp" type="hidden"/>
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.items[0].productId" paramvalue="childProduct.id" type="hidden"/>
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.items[0].quantity" type="hidden" value="1" />
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.items[0].catalogRefId" paramvalue="childSKU.id" type="hidden" />
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.pageFlow" value="true" type="hidden" />
 <dsp:input bean="/atg/commerce/order/purchase/CartModifierFormHandler.addItemToOrder" value="add" type="submit"  value="Add to Cart"/>  
</dsp:form>

Adding Multiple Items to cart:

<dsp:importbean bean="/atg/commerce/order/purchase/CartModifierFormHandler"/>
<dsp:importbean bean="/atg/dynamo/droplet/ForEach"/>
<dsp:form action="display_product.jsp" method="post">
 <input name="id" type="hidden" value='<dsp:valueof param="product.repositoryId"/>'>
 <dsp:input bean="CartModifierFormHandler.addItemToOrderSuccessURL" type="hidden" value="shoppingcart.jsp"/>
 <table border=1>
  <tr>
   <td>SKU</td>
   <td>Quantity</td>
  </tr>
  <dsp:droplet name="ForEach">
   <dsp:param name="array" param="product.childSKUs"/>
   <dsp:param name="elementName" value="sku"/>
   <dsp:param name="indexName" value="skuIndex"/>
   <dsp:oparam name="outputStart">
    <dsp:input bean="CartModifierFormHandler.addItemCount" paramvalue="size" type="hidden"/>
   </dsp:oparam>
   <dsp:oparam name="output">
    <tr>
     <td><dsp:valueof param="sku.displayName"/></td>
     <td>
      <dsp:input bean="CartModifierFormHandler.items[param:skuIndex].quantity" size="4" type="text" value="0"/>
      <dsp:input bean="CartModifierFormHandler.items[param:skuIndex].catalogRefId" paramvalue="sku.repositoryId" type="hidden"/>
      <dsp:input bean="CartModifierFormHandler.items[param:skuIndex].productId" paramvalue="product.repositoryId" type="hidden"/>
     </td>
    </tr>
   </dsp:oparam>
  </dsp:droplet>
 </table>
 <BR>
 <dsp:input bean="CartModifierFormHandler.addItemToOrder" type="submit" value="Add To Cart"/>
</dsp:form> 


0 comments:

Post a Comment

 
;