getProductOptionsAvailability( )


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

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.

Method Declaration
Copy
function getProductOptionsAvailability(
  productId: string,
  choices: ProductChoices,
): Promise<ProductOptionsAvailability>;
Method Parameters
productIdstringRequired

The ID of the product whose availability is being checked.


choicesProductChoicesRequired

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

Returns
Return Type:Promise<ProductOptionsAvailability>

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.

JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function getProductOptionsAvailability(productId, choices) { return wixStoresBackend.getProductOptionsAvailability(productId, choices); } /************* * Page code * *************/ import { getProductOptionsAvailability } from 'backend/products'; // ... let productId = // get product ID; let choices = { "Size": "Large" }; getProductOptionsAvailability(productId, choices) .then((availability) => { let available = availability.availableForPurchase; // false let options = availability.productOptions; // see below let mainMedia = availability.mainMedia; let mediaItems = availability.mediaItems; let selectedVariant = availability.selectedVariant; // null }) .catch((error) => { console.log(error); }); /* * options: * * "Size": { * "optionType": "drop_down", * "name": "Size", * "choices": [ * { * "value": "Small", * "description": "Small", * "inStock": true, * "visible": true * }, * { * "value": "Large", * "description": "Large", * "inStock": true, * "visible": true * } * ] * }, * "Color": { * "optionType": "color", * "name": "Color", * "choices": [ * { * "value": "rgb(0, 128, 0)", * "description": "green", * "inStock": true, * "visible": true * }, * { * "value": "rgb(255, 0, 0)", * "description": "red", * "inStock": true, * "visible": true * } * ] * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?