getCategory
Method fetching information about a specific category from Salesforce Commerce Cloud.
This method communicates with the getCategory endpoint of the Vue Storefront API Middleware. In turn, it receives data from the getCategory or the Get category endpoints exposed by SCAPI / OCAPI depending on the middleware configuration.
You can use this method to fetch information about a category available in the storefront catalog assigned to the current site.
Signature
export declare function getCategory(
props: CategoryGetParams
): Promise<import("commerce-sdk/dist/product/product").ShopperProducts.Category>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | CategoryGetParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
Returns
Returns a representation of a Category Hierarchy.
Referenced Types
CategoryGetParamsShopperProducts.Category
Examples
Fetching a category by id.
import { sdk } from '~/sdk.config.ts';
const category = await sdk.commerce.getCategory({ id: 'root' });Fetching a category by id and changing the levels of nested subcategories through levels.
import { sdk } from '~/sdk.config.ts';
const category = await sdk.commerce.getCategory({ id: 'root', levels: 2 });Fetching a category by id for a different than the currently active locale.
import { sdk } from '~/sdk.config.ts';
const category = await sdk.commerce.getCategory({ id: 'root', locale: 'en_US' });