type InventoryAvailabilityIndex = {
variants: {
"gold:XL": {
id: string;
sku: string;
optionValues: Record<string, string>;
available: boolean;
}
}
}
|
Tip
|
Since Catalog Browse 2.2.0, Release Train 2.3.0 |
Catalog Browse provides a consolidated summary of a product’s and its variant’s inventory availability.
This endpoint is intended to be used in commerce flows to retrieve inventory availability information for all variants of a product in a single request and replace hydrating full VariantDetails onto the ProductDetails.
The index uses the variant option values as the keys to allow fast lookup in the frontend to be used alongside option selector components to hide/grey-out unavailable options and the add-to-cart button.
type InventoryAvailabilityIndex = {
variants: {
"gold:XL": {
id: string;
sku: string;
optionValues: Record<string, string>;
available: boolean;
}
}
}
|
Tip
|
See the OpenAPI spec for the endpoint. |
Using this endpoint rather than hydrating the full variant details is particularly useful for products with large numbers (e.g., hundreds) of variants to improve performance and time to first paint.
To maximize its effect, set default variant hydration behavior for product details in Catalog Service to NONE and have the frontend make a separate call to fetch the inventory availability index in asynchronously such as in a useEffect or server function.
This allows the main content to load and be painted more quickly while the availability index is retrieved before the user can actually interact with the page.
broadleaf:
catalog:
product:
details:
variant-hydration-behavior: NONE
InventoryAvailabilityIndexService orchestrates calls to the Catalog and Inventory providers to fetch lite variant and inventory availability information for all variants of a product.
ExternalCatalogProvider#fetchLiteVariantsForProduct fetches LiteVariants as lightweight representation of a Variant with only essential information.
ExternalInventoryProvider#getInventoryAvailabilityForSkus builds a collection of SkuInventoryAvailabilityRequests from LiteVariants and calls the bulk availability API in Inventory Services.
The map key for AvailabilityInfo#variants takes the variant option values and joins each value with a semicolon in alphabetical order by key.
For example, given the following option values
{
"size": "XL",
"color": "gold"
}
The key would be gold:XL.
** To modify this behavior, extend DefaultInventoryAvailabilityIndexService#buildOptionValuesKey