Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Product Discovery initialization

The Product Discovery initializer configures search and filtering functionality, including faceted search, sorting, and product listing. Use initialization to customize search behavior and product discovery data models.

Version: 2.1.0

Configuration options

The following table describes the configuration options available for the Product Discovery initializer:

ParameterTypeReq?Description
langDefinitionsLangDefinitionsNoLanguage definitions for internationalization (i18n). Override dictionary keys for localization or branding.
modelsRecord<string, any>NoCustom data models for type transformations. Extend or modify default models with custom fields and transformers.

Basic initialization

Initialize the drop-in with default settings:

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-product-discovery';
await initializers.mountImmediately(initialize, {});

Language definitions

Override dictionary keys for localization or branding. The langDefinitions object maps locale keys to custom strings that override the drop-in’s default text.

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-product-discovery';
const customStrings = {
'AddToCart': 'Add to Bag',
'Checkout': 'Complete Purchase',
'Price': 'Cost',
};
const langDefinitions = {
default: customStrings,
};
await initializers.mountImmediately(initialize, { langDefinitions });

Customizing data models

Extend or transform data models by providing custom transformer functions. Use the models option to add custom fields or modify existing data structures returned from the backend.

Available models

The following models can be customized through the models configuration option:

ModelDescription
ProductTransforms Product data from GraphQL.
ProductSearchResultTransforms ProductSearchResult data from GraphQL.

The following example shows how to customize the Product model for the Product Discovery drop-in:

import { initializers } from '@dropins/tools/initializer.js';
import { initialize } from '@dropins/storefront-product-discovery';
const models = {
Product: {
transformer: (data) => ({
// Add custom fields from backend data
customField: data?.custom_field,
promotionBadge: data?.promotion?.label,
// Transform existing fields
displayPrice: data?.price?.value ? `$${data.price.value}` : 'N/A',
}),
},
};
await initializers.mountImmediately(initialize, { models });

Configuration types

The following TypeScript definitions show the structure of each configuration object:

langDefinitions

Maps locale identifiers to dictionaries of key-value pairs. The default locale is used as the fallback when no specific locale matches. Each dictionary key corresponds to a text string used in the drop-in UI.

langDefinitions?: {
[locale: string]: {
[key: string]: string;
};
};

models

Maps model names to transformer functions. Each transformer receives data from GraphQL and returns a modified or extended version. Use the Model<T> type from @dropins/tools to create type-safe transformers.

models?: {
[modelName: string]: Model<any>;
};

Model definitions

The following TypeScript definitions show the structure of each customizable model:

Product

export interface ProductSearchResponse {
productSearch: ProductSearchResult;
}

ProductSearchResult

export interface ProductSearchResult {
facets: SearchFacet[];
items: Product[];
pageInfo: {
currentPage: number;
totalPages: number;
totalItems: number;
pageSize: number;
};
suggestions?: string[];
totalCount: number;
metadata?: {
filterableAttributes: RefineOption[];
sortableAttributes: RefineOption[];
};
}