Skip to content

add(coupon: string): Promise<boolean>

The add is an asynchronous method which allows to add a coupon code to the basket.

Input parameters

coupon

coupon is a mandatory parameter of string type that represents the coupon that we want to add.

Returned value

A returned value has a type of Promise<boolean>. If a coupon has been added successfully it returns true, otherwise it returns false.

Example

In this example we make a basketPromotionsApi call to add a coupon code to the basket.

useStorefront(async ({ eventBus, getApi }) => {
    eventBus.on('basket.initialized', async () => {
        const basketPromotionsApi = await getApi('basketPromotionsApi');

        basketPromotionsApi.add('examplecoupon');
    });
});

Basket Promotions API methods reference