Alokai
You are reading the documentation for v7.x and earlier, which is no longer the latest version. Switch to v8.x

getUserCarts

Method fetching all customer carts from SAP Commerce Cloud.

This method sends a POST request to the getCarts endpoint of the Alokai Middleware. In turn, it exchanges data with the getCarts endpoint exposed by the SAP OCC API Carts Controller.

The method fetches customer carts based on the vsf-sap-token cookie (which is assigned to that customer). The cookie must be present in the browser for the method to work properly.

Signature

export declare function getUserCarts<Res extends CartList = CartList,
	Props extends GetAllCartsProps = GetAllCartsProps>(
	props?: Props,
	options?: MethodOptions
): Promise<Res>;

Parameters

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

Returns

Returns a representation of a Cart List.

Referenced Types

Examples

Fetching a list of all customer carts.

import { sdk } from '~/sdk';

const { carts } = await sdk.commerce.getUserCarts();

Fetching a list of customer carts and selecting response fields.

import { sdk } from '~/sdk';

const { carts } = await sdk.commerce.getUserCarts({ fields: 'carts(code)' });

Fetching a list of saved customer carts.

import { sdk } from '~/sdk';

const { carts } = await sdk.commerce.getUserCarts({ savedCartsOnly: true });

Fetching a paginated list of customer carts. The currentPage and pageSize properties have effect only when savedCartsOnly is true. Their default values are 0 and 20 respectively.

import { sdk } from '~/sdk';

const { carts } = await sdk.commerce.getUserCarts({
  savedCartsOnly: true,
  pageSize: 3,
  currentPage: 2
});

On this page