Basket Taxes API¶
Feature name: basket
Api name: basketTaxesApi
API used to perform actions related to taxes in a basket like getting a list with taxes associated with a current list of items in a basket or getting their prices.
classDiagram
direction LR
class select["select$"]
class selectSum["selectSum$"]
BasketTaxesAPI --> get
BasketTaxesAPI --> select
BasketTaxesAPI --> getSum
BasketTaxesAPI --> selectSum
class BasketTaxesAPI {
get() Tax[]
select$() Observable~Tax[]~
getSum() Price[]
selectSum$() Observable~Price[]~
}
link get "../methods/get/"
link select "../methods/select/"
link getSum "../methods/get-sum/"
link selectSum "../methods/select-sum/"
Get API¶
To get the Basket Taxes API
use its name basketTaxesApi
with the getApi
method.
useStorefront(async ({ eventBus, getApi }) => {
eventBus.on('basket.initialized', async () => {
const basketTaxesApi = await getApi('basketTaxesApi');
});
});
This API is not automatically initialized. Unless you initialize it by hand or use a proper event like in the example above, you won't be able to fetch the API. Read more in the Retrieving basket APIs section
Methods¶
- get - get a list of taxes associated with a current basket
- select$ - select a list of taxes associated with a current basket
- getSum - get a list of tax prices associated with a current basket
- selectSum$ - select a list of tax prices associated with a current basket
Example¶
In this example we make a basketTaxesApi
call to get the list of taxes for a current basket.
useStorefront(async ({ eventBus, getApi }) => {
eventBus.on('basket.initialized', async () => {
const basketTaxesApi = await getApi('basketTaxesApi');
const taxesList = basketTaxesApi.get();
});
});
Example¶
In this example we make a basketTaxesApi
call to select the list of taxes for a current basket.
useStorefront(async ({ eventBus, getApi }) => {
eventBus.on('basket.initialized', async () => {
const basketTaxesApi = await getApi('basketTaxesApi');
const taxesList$ = basketTaxesApi.select$();
});
});
Example¶
In this example we make a basketTaxesApi
call to select the list of tax prices for a current basket.
useStorefront(async ({ eventBus, getApi }) => {
eventBus.on('basket.initialized', async () => {
const basketTaxesApi = await getApi('basketTaxesApi');
const taxPrices$ = basketTaxesApi.selectSum$();
});
});