Develop Secure Code
productDetails
searchProducts
searchProductsSearches for products in a webstore. Use this wire adapter in Order Management repricing scenarios.
1import { LightningElement, wire } from 'lwc';
2import { searchProducts } from 'lightning/commerceRepricingApi';
3
4@wire(searchProducts, { webstoreId: string, version: string })
5propertyOrFunction1GET /commerce/order-management/webstores/{webstoreId}/productssearchProducts uses this Commerce API resource.
webstoreId—(Required) The ID of the webstore. The ID prefix is 0ZE.version—(Required) The API version for the adapter, for example, v62.0. Without this parameter, the wire doesn’t fire.searchTerm—(Optional) A keyword to search products by.page—(Optional) The page number of results to return.pageSize—(Optional) The number of results per page.effectiveAccountId—(Optional) The effective account ID for buyer-specific results.facets—(Optional) Facets to apply to the search.data—A ProductSearchOutputRepresentation object with these fields:
pageSize—The number of results per page.totalRecordsFound—The total number of products matching the search.pageNumber—The current page number.products—A list of matching products.facets—A list of facets for the result set.success—Indicates whether the request was successful.errors—A list of errors, if any. Each error has errorCode, message, and errorEntityId fields.error—FetchResponse1import { LightningElement, wire } from 'lwc';
2import { searchProducts } from 'lightning/commerceRepricingApi';
3
4export default class SearchProductsExample extends LightningElement {
5 webstoreId = '0ZExx0000000001';
6 searchTerm = 'widget';
7
8 @wire(searchProducts, {
9 webstoreId: '$webstoreId',
10 version: 'v62.0',
11 searchTerm: '$searchTerm',
12 page: 1,
13 pageSize: 25,
14 })
15 searchResults;
16
17 get products() {
18 return this.searchResults?.data?.products;
19 }
20
21 get totalCount() {
22 return this.searchResults?.data?.totalRecordsFound;
23 }
24}If the wire adapter encounters an error, data is undefined and error contains the error details.
See Also