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 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
The ID of the product whose availability is being checked.
Option choices to use when checking the product's availability.
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?
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.
1/*******************************2 * Backend code - products.jsw *3 *******************************/45import wixStoresBackend from 'wix-stores-backend';67export function getProductOptionsAvailability(productId, choices) {8 return wixStoresBackend.getProductOptionsAvailability(productId, choices);9}1011/*************12 * Page code *13 *************/14import { getProductOptionsAvailability } from 'backend/products';1516// ...1718let productId = // get product ID;19 let choices = {20 "Size": "Large"21 };2223getProductOptionsAvailability(productId, choices)24 .then((availability) => {25 let available = availability.availableForPurchase; // false26 let options = availability.productOptions; // see below27 let mainMedia = availability.mainMedia;28 let mediaItems = availability.mediaItems;29 let selectedVariant = availability.selectedVariant; // null30 })31 .catch((error) => {32 console.log(error);33 });3435/*36 * options:37 *38 * "Size": {39 * "optionType": "drop_down",40 * "name": "Size",41 * "choices": [42 * {43 * "value": "Small",44 * "description": "Small",45 * "inStock": true,46 * "visible": true47 * },48 * {49 * "value": "Large",50 * "description": "Large",51 * "inStock": true,52 * "visible": true53 * }54 * ]55 * },56 * "Color": {57 * "optionType": "color",58 * "name": "Color",59 * "choices": [60 * {61 * "value": "rgb(0, 128, 0)",62 * "description": "green",63 * "inStock": true,64 * "visible": true65 * },66 * {67 * "value": "rgb(255, 0, 0)",68 * "description": "red",69 * "inStock": true,70 * "visible": true71 * }72 * ]73 * }74 */75
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.
1/*******************************2 * Backend code - products.jsw *3 *******************************/45import wixStoresBackend from 'wix-stores-backend';67export function getProductOptionsAvailability(productId, choices) {8 return wixStoresBackend.getProductOptionsAvailability(productId, choices);9}1011/*************12 * Page code *13 *************/14import { getProductOptionsAvailability } from 'backend/products';1516// ...1718let productId = // get product ID19 let choices = {20 "Size": "Large",21 "Color": "Red"22 };2324getProductOptionsAvailability(productId, choices)25 .then((availability) => {26 let available = availability.availableForPurchase; // true27 let options = availability.productOptions; // see below28 let mainMedia = availability.mainMedia;29 let mediaItems = availability.mediaItems;30 let selectedVariant = availability.selectedVariant; // see below31 })32 .catch((error) => {33 console.log(error);34 });3536/*37 * options:38 *39 * "Size": {40 * "optionType": "drop_down",41 * "name": "Size",42 * "choices": [43 * {44 * "value": "Small",45 * "description": "Small",46 * "inStock": true,47 * "visible": true48 * },49 * {50 * "value": "Large",51 * "description": "Large",52 * "inStock": true,53 * "visible": true54 * }55 * ]56 * },57 * "Color":{58 * "optionType": "color",59 * "name": "Color",60 * "choices": [61 * {62 * "value": "rgb(0, 128, 0)",63 * "description": "green",64 * "inStock": true,65 * "visible": true66 * },67 * {68 * "value": "rgb(255, 0, 0)",69 * "description": "red",70 * "inStock": true,71 * "visible": true72 * }73 * ]74 * }75 *76 *77 * selectedVariant:78 *79 * "selectedVariant":{80 * "sku": "366615376135191",81 * "currency": "USD",82 * "price": 7.5,83 * "discountedPrice": 7.5,84 * "formattedPrice": "$7.50",85 * "formattedDiscountedPrice": "$7.50",86 * "visible": true,87 * "inStock": true,88 * "weight": 089 * }90 */91