ART#306 - How to add multiple items to cart in ATG?

Adding multiple items to cart is no different from adding single item to cart.
As we have already acquainted ourselves with the CartModifierFormHandler, we can now jump straight to the code.

Have a look at the below JSP Snippet:-

STEP #1: Import the component, CartModifierFormHandler.

STEP #2: Set the addItemCount of the CartModifierFormHandler to the number of different items we are adding. [In our case it is 3]

STEP #3: Set the relevant details to the items[] array of the CartModifierFormHandler as you did for adding a single item to cart.
Since we are adding 3 different items [SKUs], we use the index 0,1 and 2 respectively for setting the values of each item.
For each item, set the following properties:
  • quantity
  • catalogRefId
  • productId
  • commerceItemType ["default" for now]

STEP #4: Create a submit method corresponding to CartModifierFormHandler's handleAddItemToOrder, in the same way as adding a single item to cart.

Nice, easy and short! Let us move on and understand what is a commerceItem and how we extend them!




  1. HI ,

    Can you please put up the atg installation. As we also wants to do hands on for all this code.


  2. how will i add 3 items on cart with same sku ?

  3. The "Next" link redirects to ART#304.



Get All The Latest Updates Delivered Straight Into Your Inbox For Free!