This KB demonstrates the use of the addToCart() function to add multiple items into the current user's cart.
It is working as expected to call sn_sc.CartJS() multiple times in the script to be able to add multiple items.
- Login to any out-of-box instance as System Administrator (Or any user with admin role).
- Go to System Definition > Script - Background. And test the following script:
- We are expecting two items to be added to the user's cart, but if you check the sc_cart record for the current user, only one item got added.
(To find current user's sc_cart records, type sc_cart.list in the instance menu Filter navigator. And filter the list on the User column.)
- Now, delete all the sc_cart records for the current user.
- Test the following script in System Definition > Script - Background again:
Note "var cart = new sn_sc.CartJS();" is inside the loop now. This script adds two items into the cart.
Also see more on our developer website: