Skip to content

basket.setShipping

basket.setShipping is an event on the Event Bus that occurs whenever a shipping method is set in the basket.

Event body

none

Example

In this example we listen to basket.setShipping event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    storefront.eventBus.on('basket.setShipping', () => {
        console.log('A shipping method has been changed!');
    });
});

Example

In this example we use a Message Storage API to retrieve an array of past basket.setShipping events.

useStorefront((storefront) => {
    const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');

    const pastSetShippingEvents = messageStorageApi.getChannelMessages('basket.setShipping');

    if (pastSetShippingEvents.length > 0) {
        pastSetShippingEvents.forEach(({ body: eventBody }) => {
            console.log('perform action on every past event');
        });
    }
});

JS API reference