Alokai
You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current

getFacet

The method loads products and categories based on provided filters, as well as sorting and pagination options.

This method sends a GET request to the getFacet endpoint of the Vue Storefront API Middleware.

Signature

export declare function getFacet(
	params: GetFacetParams,
	options?: MethodBaseOptions
): Promise<GetFacetResponse>;

Parameters

NameRequiredTypeDescription
paramsRequiredGetFacetParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodBaseOptionsOptions that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of the GetFacetResponse

Referenced Types

Examples

Retrieving categories with matching slug

import { sdk } from '~/sdk.config.ts';
const { categories } = await sdk.getFacet({ categorySlug: 'men' });

Text search

import { sdk } from '~/sdk.config.ts';
const response = await sdk.commerce.getFacet({
  phrase: 'bag'
});
const allProductsMatchPhrase =
  response.results.every((product) =>
    product.name.toLowerCase().includes('bag'));

console.log(allProductsMatchPhrase // true);

Filtering by attribute. Please note that the filters key must be a name of any of the facets defined in the config file integrations.ct.configuration.faceting.availableFacets array.

const whiteBags = await sdk.commerce.getFacet({
  phrase: 'bag',
  filters: { color: ['white'] }
});

Sorting by sorting option The value of sort is an id of a sorting option define inside config in integrations.ct.configuration.faceting.sortingOptions array.

const bagsSortedByPrice = await sdk.commerce.getFacet({
  phrase: 'bag',
  sort: 'price-up'
});

Include product variants in results

const bagsWithVariants = await sdk.commerce.getFacet({
  phrase: 'bag',
  withVariants: true
});

On this page