Search.../

addProductsToCollection( )

Adds products by ID to a product collection.

Description

The addProductsToCollection() function returns a Promise that resolves when the products with the given IDs are added to a product collection with a given ID.

You can add multiple products to a collection at one time by delimiting the list of products with commas.

With this function, you can only add existing products to a collection. You cannot use the addProductsToCollection() function to create a product. See createProduct() to add a product to the store.

Syntax

function addProductsToCollection(collectionId: string, productIds: Array<string>): Promise<void>

addProductsToCollection Parameters

NAME
TYPE
DESCRIPTION
collectionId
string

ID of the product collection to which to add products.

productIds
Array<string>

IDs of the products to add to the product collection, separated by commas.

Returns

Fulfilled - When the products are added to the product collection. Rejected - Error message.

Return Type:

Promise<void>

Was this helpful?

Add products to a product collection

Copy Code
1/*******************************
2 * Backend code - products.jsw *
3 *******************************/
4
5import wixStoresBackend from 'wix-stores-backend';
6
7export function addProductsToCollection(collectionId, productIds) {
8 return wixStoresBackend.addProductsToCollection(collectionId, productIds);
9}
10
11/*************
12 * Page code *
13 *************/
14import { addProductsToCollection } from 'backend/products';
15
16// ...
17
18
19const collectionId = ... // get collection ID
20const productIds = ["id1", "id2", "id3"];
21
22addProductsToCollection(collectionId, productIds)
23 .then(() => {
24 // products added to the collection
25 })
26 .catch((error) => {
27 // products not added to the collection
28 });