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

getCart

Method fetching a cart with a given identifier from SAP Commerce Cloud.

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

When vsf-sap-token cookie is present in the browser, this method will fetch a cart for the current user. In case there is no cookie, it will fetch a cart for an anonymous user. For logged-in users, make sure to pass cart code as the cartId param. In case of anonymous users, pass cart guid instead.

Signature

export declare function getCart<Res extends Cart = Cart,
	Props extends GetCartProps = GetCartProps>(
	props: Props,
	options?: MethodOptions
): Promise<Res>;

Parameters

NameRequiredTypeDescription
propsRequiredPropsParameter 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.

Referenced Types

Examples

Fetching a cart.

import { sdk } from '~/sdk';

const cart = await sdk.commerce.getCart({ cartId: '00035084' });

Fetching a cart and selecting response fields.

import { sdk } from '~/sdk';

const cart = await sdk.commerce.getCart({ cartId: '00035084', fields: 'code,guid,user(FULL)' });

On this page