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!


Back



Next






9 comments:

  1. HI ,

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

    Regards
    Rituj

    ReplyDelete
    Replies
    1. For ATG Installation, you can see the step by step process HERE: https://learnoracleatg.blogspot.in/p/setup.html

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

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

    ReplyDelete
    Replies
    1. This has been fixed. Thanks for pointing out.

      Delete
  4. Very nice tutorials, but I suggest to add system requirements for installation and step by step installation process will help.

    ReplyDelete
    Replies
    1. Step By Step Installation is HERE: https://learnoracleatg.blogspot.in/p/setup.html

      Delete
  5. I saw in documentation that we can have multiple shopping carts for a user. Can this be implemented even if the site is not a multisite?

    ReplyDelete

Subscribe

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

Flickr