Vue Storefront is now Alokai! Learn More
GetCart

GetCart

Implements GetCart Unified Method.

Source

import { defineApi, getCartFromContext } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sapcc/udl";


declare module "@vsf-enterprise/unified-api-sapcc" {
  interface GetCartExtendedArgs {
    /**
     * Response configuration. List of fields returned in the response body.
     */
    fields?: "BASIC" | "DEFAULT" | "FULL" | string | string[];
    /**
     * Anonymous cart GUID.
     */
    oldCartId?: string;

    /**
     * GUID of the current user's cart that will be merged with the anonymous cart.
     */
    toMergeCartGuid?: string;
  }
}


export const getCart = defineApi.getCart(async (context, args) => {
  const data = await getCartFromContext(context, args);
  const { normalizeCart } = getNormalizers(context);

  return normalizeCart(data);
});