Vue Storefront is now Alokai! Learn More
GetCart

GetCart

Implements GetCart Unified Method.

Source

import { HttpStatusCode } from "@alokai/connect/middleware";

import { defineApi, getCartFromContext } from "@vsf-enterprise/unified-api-bigcommerce";
import { getNormalizedCart } from "@vsf-enterprise/unified-api-bigcommerce";

export const getCart = defineApi.getCart(async (context, args) => {
  if (args?.cartId != null) {
    throw context.createHttpError({
      message: "Multiple carts feature is not available.",
      statusCode: HttpStatusCode.BAD_REQUEST,
    });
  }
  const cart = await getCartFromContext(context);

  return await getNormalizedCart(context, cart);
});