addProductsToCart( )
Deprecated. This function will continue to work, but a newer version is available at wix-stores.cart.addProducts().
Description
The addProductsToCart()
function returns a Promise that is resolved when the
specified products are added to the shopping cart.
Migration Instructions
If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to
wix-stores.cart.addProducts()
.To migrate to the new function:
Add the new import statement:
javascript | Copy Codeimport { cart } from 'wix-stores'Look for any code that uses
$w('#shoppingCartIcon').addProductsToCart()
, and replace it with withcart.addProducts()
.Note:
'#shoppingCartIcon'
might be named differently in your code.Update your code to work with the new
cart.addProducts()
call and response properties.Test your changes to make sure your code behaves as expected.
Syntax
function addProductsToCart(products: Array<AddToCartItem>): Promise<void>
addProductsToCart Parameters
NAME
TYPE
DESCRIPTION
The list of products to add to the cart.
Returns
Fulfilled - When the products have been added to the cart.
Return Type:
Was this helpful?
Add multiple products to the cart
1// Updated example using cart.addProducts()23import { cart } from 'wix-stores';45const products = [6 {7 "productId": "580a3cd8-8e39-2863-2a56-1d7019cbfcc1",8 "quantity": 59 },10 {11 "productId": "2ab0eac2-69b3-bc77-5033-fac8805b223a",12 "quantity": 2,13 "options": {14 "choices": {15 "Size": "Small"16 },17 "customTextFields": [{18 "title": "Personalization 1",19 "value": "Personalized Text 1"20 },21 {22 "title": "Personalization 2",23 "value": "Personalized Text 2"24 }]25 }26 }27]2829cart.addProducts(products)30 .then((updatedCart) => {31 console.log("Product added");32 const cartId = updatedCart._id;33 const cartLineItems = updatedCart.lineItems;34 })35 .catch((error) => {36 console.log(error);37 });38394041// Deprecated example424344$w('#shoppingCartIcon1').addProductsToCart([45 {46 "productId": "580a3cd8-8e39-2863-2a56-1d7019cbfcc1",47 "quantity": 548 },49 {50 "productId": "2ab0eac2-69b3-bc77-5033-fac8805b223a",51 "quantity": 2,52 "options": {53 "choices": {54 "Size": "Small"55 },56 "customTextFields": [{57 "title": "Personalization 1",58 "value": "Personalized Text 1"59 },60 {61 "title": "Personalization 2",62 "value": "Personalized Text 2"63 }]64 }65 }66])67 .then(() => {68 console.log("Products added");69 })70 .catch((error) => {71 console.log(error);72 });