searchProduct
Method fetching a list of products and additional data from SAP Commerce Cloud.
This method sends a GET request to the searchProduct endpoint of the Alokai Middleware. In turn, it receives data from the getProducts endpoint exposed by the SAP OCC API Products Controller.
In the examples below, you can see how various parameter configurations passed to the SDK method affect the final query parameter sent to the SAP OCC API.
Signature
export declare function searchProduct<Res extends ProductSearchPage = ProductSearchPage,
Props extends ProductSearchProps = ProductSearchProps>(
props?: Props,
options?: MethodOptions
): Promise<Res>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Optional | Props | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns a representation of a Product Search Page. That includes products and additional data, such as available facets, sorting and pagination options. It can also include spelling suggestions.
Referenced Types
Examples
Using the method without any parameters to fetch unfiltered products and additional data.
Final query: :undefined
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct();Using the method the way it will be possible to cache the response.
Final query: :undefined
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct({ lang: 'en', currency: 'GBP' });Fetching paginated products and additional data by using the pageSize and currentPage parameters.
Final query: :undefined
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct({ pageSize: 10, currentPage: 1 });Performing a free-text search and sorting the results by using the searchTerm and sort parameters.
Final query: sneakers:topRated
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct({ searchTerm: 'sneakers', sort: 'topRated' });Performing a free-text search and selecting response fields by using the searchTerm and fields parameters. The response object will only contain the freeTextSearch key (alongside type and pagination which are always included - regardless of specified fields).
Final query: sneakers:undefined
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct({ searchTerm: 'sneakers', fields: 'freeTextSearch' });Using filters parameter to fetch products belonging to specific categories and with a specific average rating. You can view available filters (Indexed Types) and their values in the Solr Facet Search Configuration section in your SAP Backoffice.
Final query: :undefined:allCategories:collections:allCategories:brands:reviewAvgRating:4.4
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct({
filters: {
allCategories: ['collections', 'brands'],
reviewAvgRating: [4.4]
}
});Fetching the same subset of products as in the previous example, this time using the query parameter.
Final query: :undefined:allCategories:collections:allCategories:brands:reviewAvgRating:4.4
import { sdk } from '~/sdk';
const result = await sdk.commerce.searchProduct({ query: ':undefined:allCategories:collections:allCategories:brands:reviewAvgRating:4.4' });