Search...
addProductMediaToChoices( )
Adds media items by ID to product options.
Description
The addProductMediaToChoices()
function returns a Promise that resolves when the adding of
media (images or videos) to a product's options has started.
Syntax
function addProductMediaToChoices(productId: string, mediaChoices: Array<MediaChoice>): Promise<void>
addProductMediaToChoices Parameters
NAME
TYPE
DESCRIPTION
productId
string
ID of the product with choices to which to add media items.
mediaChoices
Array<MediaChoice>
Product media items, and the choices to add the media to.
Note: Media must already be added to the product.
Returns
Fulfilled - When the media items are added to the product options. Rejected - Error message.
Return Type:
Promise<void>
Related Content:
Was this helpful?
Add media items to product options
Copy Code
1/*******************************2 * Backend code - products.jsw *3 *******************************/45import wixStoresBackend from 'wix-stores-backend';67export function addProductMediaToChoices(productId, mediaData) {8 return wixStoresBackend.addProductMediaToChoices(productId, mediaData);9}1011/*************12 * Page code *13 *************/1415import { addProductMediaToChoices } from 'backend/products';1617// ...1819const productId = ...; // get product ID20const mediaSources = ["wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"];21const option = "Color";22const choice = "Blue";2324const mediaData = [{25 mediaSources,26 option,27 choice28}];2930addProductMediaToChoices(productId, mediaData)