Vue Storefront is now Alokai! Learn More
SetShippingMethod

SetShippingMethod

Implements SetShippingMethod Unified Method.

Source

import "./extended";

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

export const setShippingMethod = defineApi.setShippingMethod(async (context, args) => {
  const { api } = await context.getApiClient();
  const { shippingMethodId } = args;
  const shipmentId = getShipmentId(context);

  const cart = await api.updateShipment({
    shipmentId,
    shippingMethod: {
      id: shippingMethodId,
    },
  });

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