Skip to content

Product Details Functions

The Product Details drop-in provides API functions that enable you to programmatically control behavior, fetch data, and integrate with Adobe Commerce backend services.

Version: 1.3.5
FunctionDescription
fetchProductDataFetches product data for a given SKU.
getFetchedProductDataReturns previously fetched product data from cache..
getProductConfigurationValuesReturns the current product configuration values..
getProductDataReturns the product data for a given product SKU.
getRefinedProductReturns refined product data with specific options selected.
isProductConfigurationValidChecks if the current product configuration is valid..
setProductConfigurationValidSets a callback to be called when product configuration validity changes..
setProductConfigurationValuesSets a callback to be called when product configuration values change..

The fetchProductData function fetches product data for a given SKU. It can fetch either simple product data or refined product data with selected options.

const fetchProductData = async (
sku: string,
options?: Options
): Promise<any>
ParameterTypeReq?Description
skustringYesThe SKU (Stock Keeping Unit) of the product to fetch.
optionsOptionsNoOptional configuration including `anchors` (anchor options), `optionsUIDs` (selected option IDs), `preselectFirstOption` (whether to preselect first option), `isBundle` (whether product is a bundle), and `skipTransform` (whether to skip data transformation).

Does not emit any drop-in events.

Returns void.

The getFetchedProductData function returns previously fetched product data from cache.

const getFetchedProductData = async (
{ scope, }: { scope?: string } = {}
): Promise<ProductModel | null>
ParameterTypeReq?Description
optionsstring } = {}YesOptional configuration for retrieving cached product data.

Does not emit any drop-in events.

Returns ProductModel or null.

The getProductConfigurationValues function returns the current product configuration values.

const getProductConfigurationValues = async (
{ scope, }: { scope?: string } = {}
): ValuesModel | null
ParameterTypeReq?Description
optionsstring } = {}YesOptional configuration for retrieving product configuration values.

Does not emit any drop-in events.

Returns ValuesModel or null.

The getProductData function returns the product data for a given product SKU. It fetches data from Adobe Commerce and optionally preselects the first available option. The function calls the products query.

const getProductData = async (
sku: string,
options?: { preselectFirstOption?: boolean; optionsUIDs?: string[]; },
raw?: boolean
): Promise<ProductModel | null>
ParameterTypeReq?Description
skustringYesThe SKU (Stock Keeping Unit) of the product to fetch.
preselectFirstOptionbooleanNoWhether to automatically preselect the first available option for configurable products.
optionsUIDsstring[]NoAn array of option UIDs to preselect for the product.
rawbooleanNoWhether to return raw GraphQL data without transformation.

Does not emit any drop-in events.

Returns ProductModel or null.

The getRefinedProduct function returns refined product data with specific options selected. This is used for configurable products where options have been chosen. The function calls the refineProduct query.

const getRefinedProduct = async (
sku: string,
optionUIDs: string[],
anchorOptions?: string[],
raw?: boolean
): Promise<ProductModel | null>
ParameterTypeReq?Description
skustringYesThe SKU (Stock Keeping Unit) of the product to fetch.
optionUIDsstring[]YesAn array of option UIDs representing the selected variant.
anchorOptionsstring[]NoAnchor options for the product selection.
rawbooleanNoWhether to return raw GraphQL data without transformation.

Does not emit any drop-in events.

Returns ProductModel or null.

The isProductConfigurationValid function checks if the current product configuration is valid.

const isProductConfigurationValid = async (
{ scope, }: { scope?: string } = {}
): boolean | null
ParameterTypeReq?Description
optionsstring } = {}YesConfiguration options to validate.

Does not emit any drop-in events.

Returns boolean | null.

The setProductConfigurationValid function sets a callback to be called when product configuration validity changes.

const setProductConfigurationValid = async (
callback: (prev: boolean) => boolean,
options?: { scope?: string }
): any
ParameterTypeReq?Description
callbackprev: booleanNoA callback function that receives the validity status of the product configuration.

Emits the pdp/valid event.

Returns void.

The setProductConfigurationValues function sets a callback to be called when product configuration values change.

const setProductConfigurationValues = async (
callback: (prev: ValuesModel) => ValuesModel,
options?: { scope?: string }
): any
ParameterTypeReq?Description
callbackprev: ValuesModelNoA callback function that receives the updated product configuration values.

Emits the pdp/values event.

Returns void.

The following data models are used by functions in this drop-in.

The ProductModel object is returned by the following functions: getFetchedProductData, getProductData, getRefinedProduct.

interface ProductModel {
name: string;
sku: string;
isBundle: boolean;
addToCartAllowed: boolean;
inStock: boolean | null;
shortDescription?: string;
metaDescription?: string;
metaKeyword?: string;
metaTitle?: string;
description?: string;
images?: Image[];
videos?: Video[];
prices: Prices;
attributes?: Attribute[];
options?: Option[];
optionUIDs?: string[];
url?: string;
urlKey?: string;
externalId?: string;
externalParentId?: string;
variantSku?: string;
productType?: ProductType | undefined;
}

The Video interface defines the shape of a product video object returned as part of the ProductModel.

interface Video {
url: string;
title?: string;
description?: string;
preview?: {
url: string;
label?: string;
roles?: string[];
};
}

The ValuesModel object is returned by the following functions: getProductConfigurationValues.

interface ValuesModel {
sku: string;
quantity: number;
optionsUIDs?: string[];
enteredOptions?: Array<{ uid: string; value: string }>;
}