GetCart
Implements GetCart
Unified Method.
Source
import { defineApi } from "@vsf-enterprise/unified-api-commercetools";
import { getNormalizers } from "@vsf-enterprise/unified-api-commercetools/udl";
export const getCart = defineApi.getCart(async (context, args) => {
if (args?.cartId != null) {
throw { statusCode: 400, message: "Multiple carts feature is not available." };
}
const me = await context.api.getMe();
let cart = me.me.activeCart;
if (!cart) {
const response = await context.api.createCart();
cart = response.cart;
}
const { normalizeCart } = getNormalizers(context);
return normalizeCart(cart);
});