searchProducts

Searches for products in a webstore. Use this wire adapter in Order Management repricing scenarios.

Syntax 

1import { LightningElement, wire } from 'lwc';
2import { searchProducts } from 'lightning/commerceRepricingApi';
3
4@wire(searchProducts, { webstoreId: string, version: string })
5propertyOrFunction

Commerce API Resource 

1GET /commerce/order-management/webstores/{webstoreId}/products

searchProducts uses this Commerce API resource.

Parameters 

  • 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.

Returns 

  • 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.
  • errorFetchResponse

Usage 

1import { 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}

Error Handling 

If the wire adapter encounters an error, data is undefined and error contains the error details.

See Also

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.