Adds media items by ID to product options.
The addProductMediaToChoices()
function returns a Promise that resolves when the adding of
media (images or videos) to a product's options has started.
function addProductMediaToChoices(
productId: string,
mediaChoices: Array<MediaChoice>,
): Promise<void>;
ID of the product with choices to which to add media items.
Product media items, and the choices to add the media to.
Note: Media must already be added to the product.
/*******************************
* Backend code - products.jsw *
*******************************/
import wixStoresBackend from 'wix-stores-backend';
export function addProductMediaToChoices(productId, mediaData) {
return wixStoresBackend.addProductMediaToChoices(productId, mediaData);
}
/*************
* Page code *
*************/
import { addProductMediaToChoices } from 'backend/products';
// ...
const productId = ...; // get product ID
const mediaSources = ["wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"];
const option = "Color";
const choice = "Blue";
const mediaData = [{
mediaSources,
option,
choice
}];
addProductMediaToChoices(productId, mediaData)
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.