addCouponToBasket
Adds a coupon to an existing basket.
This method communicates with the addCouponToBasket endpoint of the Vue Storefront API Middleware. In turn, it receives data from the addCouponToBasket or the Update basket with coupon endpoints exposed by SCAPI / OCAPI depending on the middleware configuration.
Possible Responses
400 | InvalidCouponCodeException - the coupon number is not provided - the coupon code specified is invalid.
Signature
export declare function addCouponToBasket(
props: BasketCouponAddParams & {
basketId?: string;
}
): Promise<import("commerce-sdk/dist/checkout/checkout").ShopperBaskets.Basket>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | BasketCouponAddParams & { basketId?: string; } | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
Returns
Returns a representation of a Basket object.
Referenced Types
BasketCouponAddParamsShopperBaskets.Basket
Examples
Adding a coupon code by code.
import { sdk } from '~/sdk.config.ts';
const data: BasketCouponAddParams = {
code: 'testCoupon',
};
const basket = await sdk.commerce.addCouponToBasket(data);