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 ({ eventBus, getApi }) => {
    eventBus.on('basket.initialized', async () => {
        const basketProductsApi = await getApi('basketProductsApi');

        const basketShippingOptions = basketShippingsApi.get();

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

Basket Address API methods reference

Models reference