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:
- 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!