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!
HI ,
ReplyDeleteCan you please put up the atg installation. As we also wants to do hands on for all this code.
Regards
Rituj
For ATG Installation, you can see the step by step process HERE: https://learnoracleatg.blogspot.in/p/setup.html
Deletehow will i add 3 items on cart with same sku ?
ReplyDeleteThe "Next" link redirects to ART#304.
ReplyDeleteThis has been fixed. Thanks for pointing out.
DeleteVery nice tutorials, but I suggest to add system requirements for installation and step by step installation process will help.
ReplyDeleteStep By Step Installation is HERE: https://learnoracleatg.blogspot.in/p/setup.html
DeleteI 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?
ReplyDeleteYes, this is possible.
Delete