addItem(addItemOptions: TAddItemOptions): Promise<Basket | null>¶
The addItem
method allows to refresh the contents of a current basket.
Input parameters¶
addItemOptions¶
addItemOptions
is a mandatory parameter of the TAddItemOptions type that represents an object of details regarding the item we want to add to the basket.
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 exist then it returns null
.
Example¶
In this example we make a basketUpdaterApi
call to add an item to the basket.
useStorefront(async (storefront) => {
const basketUpdaterApi = storefront.getApiSync('basketUpdaterApi');
const item = {
variantId: 144,
quantity: 1,
variantOptions: {
"2": "16"
},
showAddedModal: false,
bundleItems: []
};
basketUpdaterApi.addItem(item);
});
Basket Updater API methods reference¶
- getBasket - Retrieve the contents of a basket
- getCurrentBasket - Retrieve the current active basket
- refreshBasket - Refresh the contents of a 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