You are reading the documentation for v7.x and earlier, which is no longer the latest version. Switch to v8.x
getCart
Get cart with a given identifier from SAP Commerce Cloud.
This method exchanges data with the getCart endpoint exposed by the SAP OCC API Carts Controller.
When vsf-sap-token cookie is present in the request, 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(
context: SapccIntegrationContext,
props: GetCartProps
): Promise<Cart>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | SapccIntegrationContext | |
props | Required | GetCartProps | 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 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)' });