add(coupon: string): Promise<void>¶
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<void>
as this method returns nothing.
Example¶
In this example we make a basketPromotionsApi
call to add a coupon code to the basket.
useStorefront(async (storefront) => {
let basketPromotionsApi = storefront.getApiSync('basketPromotionsApi');
if (!basketPromotionsApi) {
const featureSystemApi = this.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketPromotionsApi = storefront.getApiSync('basketPromotionsApi');
}
basketPromotionsApi.add('examplecoupon');
});