Skip to content

getCurrentBasket(basketId: string, omitCache = false): Promise<Basket | null>

The getCurrentBasket method allows to retrieve the contents of a currently active basket with a given id.

Input parameters

basketId

basketId is a mandatory parameter of the string type that represents the id of the basket we want to get.

omitCache (optional)

omitCache is an optional parameter of the boolean type that represents whether a method should take an attempt to retrieve a basket from the cache or just fetch it from the server. By default it is set to false.

Returned value

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

Example

In this example we make a basketUpdaterApi call to retrieve the contents of a currently active basket with a given id.

useStorefront(async (storefront) => {
    const basketUpdaterApi = storefront.getApiSync('basketUpdaterApi');

    const currentBasket = basketUpdaterApi.getCurrentBasket(12);

    console.log('list of products in a current basket:', basket.products.list);
});

Basket Updater API methods reference