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>

Media items already uploaded to the Wix site, and the choices to which to upload the media.

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 *******************************/
4
5import wixStoresBackend from 'wix-stores-backend';
6
7export function addProductMediaToChoices(productId, mediaData) {
8 return wixStoresBackend.addProductMediaToChoices(productId, mediaData);
9}
10
11/*************
12 * Page code *
13 *************/
14
15import { addProductMediaToChoices } from 'backend/products';
16
17// ...
18
19const productId = ...; // get product ID
20const mediaSources = ["wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"];
21const option = "Color";
22const choice = "Blue";
23
24const mediaData = [{
25 mediaSources,
26 option,
27 choice
28}];
29
30addProductMediaToChoices(productId, mediaData)