Skip to content

refreshBasket(): Promise<Basket | null>

The refreshBasket method allows to refresh the contents of a current basket.

Returned value

A returned value has a type of Promise<Basket | null>. If a basket exists and has been refreshed then it returns a Basket model. If it doesn't exist then it returns null.

Example

In this example we make a basketUpdaterApi call to refresh the basket each time a user logs in. We use a selectIsAuthorized$() method from Authentication API to get an observable indicating whether some user is currently logged in or not.

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

        authenticationApi.selectIsAuthorized$().subscribe((isAuthorized) => {
            if (isAuthorized == true) {
                basketUpdaterApi.refreshBasket();
            }
        });
    });
});

Basket Updater API methods reference