Skip to content

setShippingAddress(action: BasketAction, address: TBasketAddressDTO): Promise<Record<string, string[]> | undefined>

The setShippingAddress is an asynchronous method allowing to change a value of a shipping address in a basket. It is recommended to use this method while updating a value of an address because of convenient validation provided by getSectionValidation and selectSectionValidation methods.

Input parameters

action

action is a mandatory parameter of the BasketAction type that represents the action that we want to perform with a shipping address.

address

address is a mandatory parameter of the TBasketAddressDTO type which represents a new value of the shipping address.

Returned value

A returned value has a type of Promise<Record<string, string[]> | undefined> with the field ids as keys and their potential errors and messages they may have occurred during the change process as their values.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

In this example we make a basketAddressesApi call to set a new value of a shipping address. We also use a getActions method from Basket Overall API to get the action for changing the shipping address.

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

    if (!basketAddressesApi || !basketOverallApi) {
        const featureSystemApi = this.getApiSync('FeatureSystemApi');
        await featureSystemApi.registerDynamic('basket');

        basketAddressesApi = storefront.getApiSync('basketAddressesApi');
        basketOverallApi = storefront.getApiSync('basketOverallApi');
    }

    const changeShippingAddressAction = basketOverallApi.getActions().changeShippingAddress;


    await basketAddressesApi.setShippingAddress(changeShippingAddressAction, {
        isCompany: false,
        companyName: '',
        firstName: 'John',
        lastName: 'Snow',
        personalIdNumber: '',
        taxId: '',
        countryId: 'US',
        city: 'My City',
        postalCode: '12-345',
        street: 'example street 8',
        street2: '',
        phone: '123456789',
        state: '',
        useAsBillingAddress: false,
        createUserAccount: false
    });
});

Basket Address API methods reference

Objects reference

Models reference