You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current
getStores
Method fetching the list of stores
This method sends a GET request to the getStores endpoint of the Vue Storefront API Middleware. In turn, it fetches a stores from commercetools by sending a request to its GraphQL API. The default GraphQL query used by this method can be found here.
Signature
export declare function getStores<Res extends PartialGetStoresResponse = GetStoresResponse>(
params?: GetStoresParams,
options?: MethodOptions<CustomQuery<"stores">>
): Promise<Res>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
params | Optional | GetStoresParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions<CustomQuery<"stores">> | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns a representation of the GetStoresResponse.
Referenced Types
Examples
Fetching list of stores.
import { sdk } from '~/sdk.config.ts';
const result = await sdk.commerce.getStores();Fetching list of stores the way, that the response is cacheable, by passing variables explicitly instead of getting values from cookies.
import { sdk } from '~/sdk.config.ts';
const result = await sdk.commerce.getStores({
locale: "en"
});Fetching paginated list of stores.
import { sdk } from '~/sdk.config.ts';
const result = await sdk.commerce.getStores({
limit: 10,
offset: 1
});Creating a custom query to modify the response.
module.exports = {
integrations: {
ct: {
// ...
customQueries: {
'get-stores-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query stores(
$where: String
$sort: [String!]
$limit: Int
$offset: Int
) {
stores(
where: $where
sort: $sort
limit: $limit
offset: $offset
) {
${metadata?.fields}
}
}
`
}),
}
}
}
};Fetching list of stores with custom query.
const customQuery = \{ stores: "get-stores-custom-query", metadata: \{ fields: "count offset results \{ name (locale: $locale) \}", \}, \};
const result = await sdk.commerce.getStores(\{\}, \{ customQuery \});
// result will be modified by the custom query