Vue Storefront is now Alokai! Learn More
SetCartAddress

SetCartAddress

Implements SetCartAddress Unified Method.

Source

import { getNormalizers } from "@alokai/connect/integration-kit";
import { cartActions } from "@vsf-enterprise/commercetools-api";

import { defineApi, getCartVersion } from "@vsf-enterprise/unified-api-commercetools";

export const setCartAddress = defineApi.setCartAddress(async (context, args) => {
  const version = await getCartVersion(context);
  const { normalizeCart, unnormalizeAddress } = getNormalizers(context);

  const { api } = await context.getApiClient();
  const updatedCart = await api.updateCart({
    ...version,
    actions: [
      cartActions.setShippingMethodAction(),
      cartActions.setShippingAddressAction(unnormalizeAddress(args.shippingAddress)),
    ],
  });

  return normalizeCart(updatedCart.cart);
});