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 ({ eventBus, getApi }) => {
eventBus.on('basket.initialized', async () => {
const basketUpdaterApi = await getApi('basketUpdaterApi');
const currentBasket = basketUpdaterApi.getCurrentBasket(12);
console.log('list of products in a current basket:', basket.products.list);
});
});
Basket Updater API methods reference¶
- getBasket - Retrieve the contents of a basket
- refreshBasket - Refresh the contents of a basket
- addItem - Add an item to the basket
- emitUpdateBasketEvent - Emit an update basket event
- uploadVariantFile - Upload a file for a variant
- placeOrder - Place an order using the basket
- queueOrder - Queue an order for processing