getOptionsAvailability( )
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 the choices
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 choices specified in the choices
parameter 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 getOptionsAvailability(productId: string, choices: Object): Promise<ProductOptionsAvailability>
getOptionsAvailability Parameters
NAME
TYPE
DESCRIPTION
The ID of the product whose availability is being checked.
Option choices to use when checking the product's availability in the form of an object containing a key:value pair for each product option. For example, if a product has a size option, the key will be something like "Size" and its value will be something like "Large".
Returns
Fulfilled - The availability information of the product.
Return Type:
NAME
TYPE
DESCRIPTION
Whether the product with the specified option choices is available for purchase.
An object representing all the available options for a store product.
Main product media item (image or video) URL.
List of product media items.
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 by specifying an option choice. Since all the product's options have a corresponding choice, a variant is selected.
1import { product } from 'wix-stores-frontend';23const productId = "91f7ac8b-2baa-289c-aa50-6d64764f35d3";4const choices = {5 "Weight": "250g",6 "Ground for": "Stovetop"7};89product.getOptionsAvailability(productId, choices)10 .then((availability) => {11 const available = availability.availableForPurchase;12 const options = availability.productOptions;13 const mainMedia = availability.mainMedia;14 const mediaItems = availability.mediaItems;15 const selectedVariant = availability.selectedVariant;16 })17 .catch((error) => {18 console.log(error);19 });202122/*23 * Example of returned availability object:24 *25 * {26 * "availableForPurchase": true,27 * "productOptions": {28 * "Weight": {29 * "optionType": "drop_down",30 * "name": "Weight",31 * "choices": [32 * {33 * "value": "250g",34 * "description": "250g",35 * "inStock": true,36 * "visible": true,37 * "mainMedia": "null",38 * "mediaItems": []39 * },40 * {41 * "value": "500g",42 * "description": "500g",43 * "inStock": true,44 * "visible": true,45 * "mainMedia": "null",46 * "mediaItems": []47 * }48 * ]49 * },50 * "Ground for": {51 * "optionType": "drop_down",52 * "name": "Ground for",53 * "choices": [54 * {55 * "value": "Stovetop",56 * "description": "Stovetop",57 * "inStock": true,58 * "visible": true,59 * "mainMedia": "null",60 * "mediaItems": []61 * },62 * {63 * "value": "Filter",64 * "description": "Filter",65 * "inStock": true,66 * "visible": true,67 * "mainMedia": "null",68 * "mediaItems": []69 * }70 * ]71 * }72 * },73 * "mainMedia": "null",74 * "mediaItems": [],75 * "selectedVariant": {76 * "sku": "10001",77 * "currency": "USD",78 * "price": 35,79 * "discountedPrice": 30,80 * "formattedPrice": "$35.00",81 * "formattedDiscountedPrice": "$30.00",82 * "visible": true,83 * "inStock": true,84 * "weight": 0.2585 * }86 * }87 *88 */