Vue Storefront is now Alokai! Learn More
SetShippingMethod

SetShippingMethod

Implements SetShippingMethod 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 setShippingMethod = defineApi.setShippingMethod(async (context, args) => {
  const version = await getCartVersion(context);

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

  const { normalizeCart } = getNormalizers(context);

  return normalizeCart(updatedCart.cart);
});