Skip to content

Basket Updater API

API used to perform actions related to addresses in a basket like getting the addresses, changing their values or validating them.

classDiagram
direction LR
    BasketUpdaterAPI --> getBasket
    BasketUpdaterAPI --> getCurrentBasket
    BasketUpdaterAPI --> refreshBasket
    BasketUpdaterAPI --> addItem
    BasketUpdaterAPI --> emitUpdateBasketEvent
    BasketUpdaterAPI --> emitUpdateBasketEvent
    BasketUpdaterAPI --> uploadVariantFile
    BasketUpdaterAPI --> placeOrder
    BasketUpdaterAPI --> queueOrder

    class BasketUpdaterAPI {
        getBasket(basketId: string) Promise~Basket|null~
        getCurrentBasket(basketId: string, omitCache?: boolean) Promise~Basket|null~
        refreshBasket() Promise~Basket|null~
        addItem(addItemOptions: TAddItemOptions) Promise~Basket|null~
        emitUpdateBasketEvent(basket: TBasketResponse) void
        uploadVariantFile(productId: number, file: File) Promise~TFileUploadResponse|null~
        placeOrder(action: BasketAction, shouldRedirect: boolean) Promise~void~
        queueOrder(action: BasketAction) Promise~void~
    }

    link getBasket "../methods/get-basket/"
    link getCurrentBasket "../methods/get-current-basket/"
    link refreshBasket "../methods/refresh-basket/"
    link addItem "../methods/add-item/"
    link emitUpdateBasketEvent "../methods/emit-update-basket-event/"
    link uploadVariantFile "../methods/upload-variant-file/"
    link placeOrder "../methods/place-order/"
    link queueOrder "../methods/queue-order/"

Get API

To get the Basket Updater API use its name basketUpdaterApi with the getApiSync method.

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

Methods

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);
});

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);
});

Example

In this example we make a basketUpdaterApi call to place an order. We also retrieve a place order action with the help of a basketOverallApi

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

    const placeOrderAction = basketOverallApi.getActions().placeOrder;

    basketUpdaterApi.placeOrder(placeOrderAction, false);
});

Example

In this example we make a basketUpdaterApi call to queue an order for processing. We also retrieve a queue order action with the help of a basketOverallApi

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

    const queueOrderAction = basketOverallApi.getActions().queueOrder;

    basketUpdaterApi.queueOrder(queueOrderAction);
});

Objects Reference