Vue Storefront is now Alokai! Learn More
GetCart

GetCart

Implements GetCart Unified Method.

Source

import { getNormalizers } from "@alokai/connect/integration-kit";
import { HttpStatusCode } from "@alokai/connect/middleware";

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

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

  const cart = await getCartFromContext(context);
  const { normalizeCart } = getNormalizers(context);

  return normalizeCart(cart);
});