Search.../

getProductOptionsAvailability( )

Gets the availability of a product based on the specified option choices.

Description

The getProductOptionsAvailability() function returns a Promise that is resolved to a ProductOptionsAvailability object when the product's availability information about the product is retrieved.

The information returned in the selectedVariant and availableForPurchase properties reflects the option choices passed in using the ProductChoices parameter.

If the specified choices result in the selection of a single product variant, that variant is returned in the selectedVariant property and the availableForPurchase property indicates whether that product variant is available for purchase.

If the specified choices do not result in the selection of a single product variant, no variant is returned in the selectedVariant property and the availableForPurchase property will be false.

Syntax

function getProductOptionsAvailability(productId: string, choices: ProductChoices): Promise<ProductOptionsAvailability>

getProductOptionsAvailability Parameters

NAME
TYPE
DESCRIPTION
productId

string

The ID of the product whose availability is being checked.

choices

ProductChoices

Option choices to use when checking the product's availability.

Returns

Fulfilled - The availability information of the product.

Return Type:

Promise<ProductOptionsAvailability>
NAME
TYPE
DESCRIPTION
availableForPurchase

boolean

Whether the product with the specified option choices is available for purchase.

productOptions

ProductOptions

An object representing all the available options for a store product.

mainMedia

string

Main product media item (image or video) URL.

mediaItems

MediaItem

List of product media items.

selectedVariant

ProductOptionsAvailabilitySelectedVariant

The variant of the product selected using the specified option choices if there is one.

Related Content:

Was this helpful?

Get a product's availability information

This example gets a product's availability information using an option choice. The product contains more than one option, so no variant is selected and the product with the specified choices is not available for purchase.

Code Example

Copy Code
1import wixStores from 'wix-stores';
2
3// ...
4
5let productId = // get product ID
6let choices = {
7 "Size": "Large"
8};
9
10wixStores.getProductOptionsAvailability(productId, choices)
11 .then( (availability) => {
12 let available = availability.availableForPurchase; // false
13 let options = availability.productOptions; // see below
14 let mainMedia = availability.mainMedia;
15 let mediaItems = availability.mediaItems;
16 let selectedVariant = availability.selectedVariant; // null
17 } )
18 .catch( (error) => {
19 console.log(error);
20 } );
21
22/*
23 * options:
24 *
25 * "Size":{
26 * "optionType":"drop_down",
27 * "name":"Size",
28 * "choices":[
29 * {
30 * "value":"Small",
31 * "description":"Small",
32 * "inStock":true,
33 * "visible":true
34 * },
35 * {
36 * "value":"Large",
37 * "description":"Large",
38 * "inStock":true,
39 * "visible":true
40 * }
41 * ]
42 * },
43 * "Color":{
44 * "optionType":"color",
45 * "name":"Color",
46 * "choices":[
47 * {
48 * "value":"rgb(0, 128, 0)",
49 * "description":"green",
50 * "inStock":true,
51 * "visible":true
52 * },
53 * {
54 * "value":"rgb(255, 0, 0)",
55 * "description":"red",
56 * "inStock":true,
57 * "visible":true
58 * }
59 * ]
60 * }
61 */
Get a product's availability information

This example gets a product's availability information using multiple option choices. Since all the product's options have a corresponding choice, a variant is selected.

Code Example

Copy Code
1import wixStores from 'wix-stores';
2
3// ...
4
5let productId = // get product ID
6let choices = {
7 "Size": "Large",
8 "Color": "Red"
9};
10
11wixStores.getProductOptionsAvailability(productId, choices)
12 .then( (availability) => {
13 let available = availability.availableForPurchase; // true
14 let options = availability.productOptions; // see below
15 let mainMedia = availability.mainMedia;
16 let mediaItems = availability.mediaItems;
17 let selectedVariant = availability.selectedVariant; // see below
18 } )
19 .catch( (error) => {
20 console.log(error);
21 } );
22
23/*
24 * options:
25 *
26 * "Size":{
27 * "optionType":"drop_down",
28 * "name":"Size",
29 * "choices":[
30 * {
31 * "value":"Small",
32 * "description":"Small",
33 * "inStock":true,
34 * "visible":true
35 * },
36 * {
37 * "value":"Large",
38 * "description":"Large",
39 * "inStock":true,
40 * "visible":true
41 * }
42 * ]
43 * },
44 * "Color":{
45 * "optionType":"color",
46 * "name":"Color",
47 * "choices":[
48 * {
49 * "value":"rgb(0, 128, 0)",
50 * "description":"green",
51 * "inStock":true,
52 * "visible":true
53 * },
54 * {
55 * "value":"rgb(255, 0, 0)",
56 * "description":"red",
57 * "inStock":true,
58 * "visible":true
59 * }
60 * ]
61 * }
62 *
63 *
64 * selectedVariant:
65 *
66 * "selectedVariant":{
67 * "sku":"366615376135191",
68 * "currency":"USD",
69 * "price":7.5,
70 * "discountedPrice":7.5,
71 * "formattedPrice":"$7.50",
72 * "formattedDiscountedPrice":"$7.50",
73 * "visible":true,
74 * "inStock":true,
75 * "weight":0
76 * }
77 */