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 (storefront) => {
    const authenticationApi = storefront.getApiSync('AuthenticationApi');
    const basketUpdaterApi = storefront.getApiSync('basketUpdaterApi');

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

Basket Updater API methods reference