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
ID of the product collection to which to add products.
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:
Was this helpful?
Add products to a product collection
1/*******************************2 * Backend code - products.jsw *3 *******************************/45import wixStoresBackend from 'wix-stores-backend';67export function addProductsToCollection(collectionId, productIds) {8 return wixStoresBackend.addProductsToCollection(collectionId, productIds);9}1011/*************12 * Page code *13 *************/14import { addProductsToCollection } from 'backend/products';1516// ...171819const collectionId = ... // get collection ID20const productIds = ["id1", "id2", "id3"];2122addProductsToCollection(collectionId, productIds)23 .then(() => {24 // products added to the collection25 })26 .catch((error) => {27 // products not added to the collection28 });