Skip to content

setShipping(shipping: BasketShipping): void

The setShipping method allows to set the shipping option for the basket.

Input parameters

shipping

shipping is a mandatory parameter of the BasketShipping type that represents the shipping we want to add.

Returned value

A returned value has a type of void as this method returns nothing.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

In this example we make a basketShippingsApi call to set the first available shipping option as a current shipping option for the basket.

useStorefront(async (storefront) => {
    let basketShippingsApi = storefront.getApiSync('basketShippingsApi');

    if (!basketShippingsApi) {
        const featureSystemApi = this.getApiSync(FEATURE_SYSTEM_API_NAME);
        await featureSystemApi.registerDynamic('basket');

        basketShippingsApi = storefront.getApiSync('basketShippingsApi');
    }

    const basketShippingOptions = basketShippingsApi.get();

    basketShippingsApi.set(basketShippingOptions[0]);
});

Basket Address API methods reference

Models reference