Skip to content

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