SetShippingMethod
Implements SetShippingMethod
Unified Method.
Source
import { defineApi, getNormalizedCart, getShipmentId } from "@vsf-enterprise/unified-api-sfcc";
import { BasketAddress } from "@vsf-enterprise/sfcc-types";
import from "@vsf-enterprise/unified-api-sfcc/udl";
declare module "@vsf-enterprise/unified-api-sfcc" {
interface SetShippingMethodExtendedArgs {
/**
* The shipment's shipping address
*/
shippingAddress?: BasketAddress;
/**
* Whether this is a gift shipment for packaging purposes
*/
gift?: boolean;
/**
* Gift message for the shipment, if applicable
*/
giftMessage?: string;
}
}
export const setShippingMethod = defineApi.setShippingMethod(async (context, args) => {
const { shippingMethodId } = args;
const shipmentId = getShipmentId(context);
const cart = await context.api.updateShipment({
shipmentId,
shippingMethod: {
id: shippingMethodId,
},
});
return await getNormalizedCart(context, cart);
});