setShipping(shipping: BasketShipping): void¶
The setShipping
method allows to set the shipping option for the basket.
Input parameters¶
shipping¶
shipping
is a mandatory parameter of the BasketShipping type that represents the shipping we want to add.
Returned value¶
A returned value has a type of void
as this method returns nothing.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- FlashMessengerApi.addFlashMessages - when handling messages that come from a server
- basket.setShipping - when updating a shipping in a basket
- basket.basketUpdated - when updating a basket after a successful change of a country
- basket.unexpectedError - when handling unexpected errors
Example¶
In this example we make a basketShippingsApi
call to set the first available shipping option as a current shipping option for the basket.
useStorefront(async (storefront) => {
let basketShippingsApi = storefront.getApiSync('basketShippingsApi');
if (!basketShippingsApi) {
const featureSystemApi = this.getApiSync(FEATURE_SYSTEM_API_NAME);
await featureSystemApi.registerDynamic('basket');
basketShippingsApi = storefront.getApiSync('basketShippingsApi');
}
const basketShippingOptions = basketShippingsApi.get();
basketShippingsApi.set(basketShippingOptions[0]);
});
Basket Address API methods reference¶
- get
- select
- setPickupPoint
- getSelectedShipping
- selectSelectedShipping
- getAvailableShippingCountries
- selectAvailableShippingCountries
- getSelectedShippingCountry
- selectSelectedShippingCountry
- setCountry
- getPaymentCostForActiveShippingByPaymentId
- selectPaymentCostForActiveShippingByPaymentId
- isEveryAvailablePaymentFree
- selectIsEveryAvailablePaymentFree
- getSectionValidation
- selectSectionValidation
- addMap
- showPickupPointMap
- shouldDisplayRemainingBasketValueForFreeShippingMessage
- addShippingInfo
- getShippingInfo