Search.../

getProductOptionsAvailability( )

Deprecated. This function will continue to work, but a newer version is available at wix-stores.product.getOptionsAvailability().

Description

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

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-stores.product.getOptionsAvailability().

To migrate to the new function:

  1. Add the new import statement:

    import { product } from 'wix-stores'
    javascript | Copy Code
  2. If you plan to migrate all functions that use wix-stores, remove the original import wixStores statement.

  3. Look for any code that uses wixStores.getProductOptionsAvailability(), and replace it with product.getOptionsAvailability(). Update your code to work with the new product.getOptionsAvailability() call and response properties.

  4. Test your changes to make sure your code behaves as expected.

Syntax

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

getProductOptionsAvailability Parameters

NAME
TYPE
DESCRIPTION
productId
string

The ID of the product whose availability is being checked.

choices
Object

Option choices to use when checking the product's availability in the form of an object containing a key:value pair for each product choice. For example, if a product has a size choice, this key value will be something like "Size" and its value will be something like "Large".

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.

Was this helpful?

Get a product's availability information

This example gets a product's availability information by specifying an option choice. Since all the product's options have a corresponding choice, a variant is selected.

Copy Code
1// Updated example using product.getOptionsAvailability()
2
3import { product } from 'wix-stores';
4
5const productId = "91f7ac8b-2baa-289c-aa50-6d64764f35d3";
6const choices = {
7 "Weight": "250g",
8 "Ground for": "Stovetop"
9};
10
11product.getOptionsAvailability(productId, choices)
12 .then((availability) => {
13 const available = availability.availableForPurchase;
14 const options = availability.productOptions;
15 const mainMedia = availability.mainMedia;
16 const mediaItems = availability.mediaItems;
17 const selectedVariant = availability.selectedVariant;
18 })
19 .catch((error) => {
20 console.log(error);
21 });
22
23
24/*
25 * Example of returned availability object:
26 *
27 * {
28 * "availableForPurchase": true,
29 * "productOptions": {
30 * "Weight": {
31 * "optionType": "drop_down",
32 * "name": "Weight",
33 * "choices": [
34 * {
35 * "value": "250g",
36 * "description": "250g",
37 * "inStock": true,
38 * "visible": true,
39 * "mainMedia": "null",
40 * "mediaItems": []
41 * },
42 * {
43 * "value": "500g",
44 * "description": "500g",
45 * "inStock": true,
46 * "visible": true,
47 * "mainMedia": "null",
48 * "mediaItems": []
49 * }
50 * ]
51 * },
52 * "Ground for": {
53 * "optionType": "drop_down",
54 * "name": "Ground for",
55 * "choices": [
56 * {
57 * "value": "Stovetop",
58 * "description": "Stovetop",
59 * "inStock": true,
60 * "visible": true,
61 * "mainMedia": "null",
62 * "mediaItems": []
63 * },
64 * {
65 * "value": "Filter",
66 * "description": "Filter",
67 * "inStock": true,
68 * "visible": true,
69 * "mainMedia": "null",
70 * "mediaItems": []
71 * }
72 * ]
73 * }
74 * },
75 * "mainMedia": "null",
76 * "mediaItems": [],
77 * "selectedVariant": {
78 * "sku": "10001",
79 * "currency": "USD",
80 * "price": 35,
81 * "discountedPrice": 30,
82 * "formattedPrice": "$35.00",
83 * "formattedDiscountedPrice": "$30.00",
84 * "visible": true,
85 * "inStock": true,
86 * "weight": 0.25
87 * }
88 * }
89 *
90 */
91
92
93// Deprecated example
94
95import wixStores from 'wix-stores';
96
97const productId = "91f7ac8b-2baa-289c-aa50-6d64764f35d3";
98const choices = {
99 "Size": "Large",
100 "Color": "Red"
101};
102
103wixStores.getProductOptionsAvailability(productId, choices)
104 .then((availability) => {
105 const available = availability.availableForPurchase;
106 const options = availability.productOptions;
107 const mainMedia = availability.mainMedia;
108 const mediaItems = availability.mediaItems;
109 const selectedVariant = availability.selectedVariant;
110 })
111 .catch((error) => {
112 console.log(error);
113 });