addProducts( )


Deprecated. This function will continue to work, but a newer version is available at wix-ecom-backend.currentCart.addToCurrentCart().

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.currentCart.addToCurrentCart().

To migrate to the new function:

  1. Add the new import statement:

    Copy
  2. Look for any code that uses cart.addProducts(), and replace it with currentCart.addToCurrentCart(). Update your code to work with the new currentCart.addToCurrentCart() call and response properties.

    To help with updating your code to work with the new currentCart.addToCurrentCart() properties, learn more about integrating Wix Stores with the Wix eCommerce.

  3. Test your changes to make sure your code behaves as expected.

Adds one or more products to the cart.

The addProducts() function returns a Promise that is resolved when the specified products are added to the cart.

Use the quantity property of each AddToCartItem object that is passed to the products parameter to add one or more products to the cart at one time.

Use the options property of each AddToCartItem object that is passed to the products parameter to specify the product options to choose when adding the product to the cart. For example, if a product comes in different sizes, you can specify the size that should be added to the cart. If the product you are adding to the cart has options, you must specify which options should be chosen.

You can see a product's option information in the productOptions field in the Stores/Products collection.

You can use product.getOptionsAvailability() to determine if an item with specific options is available for purchase.

Note: If you use wix-stores-backend.createProduct() immediately before adding that product to the cart, we suggest setting a timeout for "1000" milliseconds (1 second) before calling cart.addProducts(). While this slows down the operation slightly, it also ensures proper retrieval of the newly created product before adding it to the cart.

Method Declaration
Copy
Method Parameters
productsArray<AddToCartItem>Required

One or more products to be added to the cart.

Returns
Return Type:Promise<CartObj>
Did this help?