SetShippingMethod
Implements SetShippingMethod
Unified Method.
Source
import { getCartId, defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vsf-enterprise/unified-api-sapcc/udl";
declare module "@vsf-enterprise/unified-api-sapcc" {
interface SetShippingMethodExtendedArgs {
/**
* Response configuration. List of fields returned in the response body.
*/
fields?: "BASIC" | "DEFAULT" | "FULL" | string | string[];
}
}
export const setShippingMethod = defineApi.setShippingMethod(async (context, args) => {
const cartId = getCartId(context);
const { shippingMethodId: deliveryModeId } = args;
const { normalizeCart } = getNormalizers(context);
await context.api.replaceCartDeliveryMode({ cartId, deliveryModeId });
const { data: cart } = await context.api.getCart({ cartId });
return normalizeCart(cart);
});