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 getApiSync
method.
useStorefront(async (storefront) => {
const basketTaxesApi = storefront.getApiSync('basketTaxesApi');
});
This API is not automatically initialized. Unless you initialize it by hand, you won't be able to fetch the API. To do it you can use the registerDynamic method from the Feature System API. Here is an example on how to do it:
useStorefront(async (storefront) => {
const featureSystemApi = this.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
const basketTaxesApi = storefront.getApiSync('basketTaxesApi');
});
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 (storefront) => {
let basketTaxesApi = storefront.getApiSync('basketTaxesApi');
if (!basketTaxesApi) {
const featureSystemApi = this.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketTaxesApi = storefront.getApiSync('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 (storefront) => {
let basketTaxesApi = storefront.getApiSync('basketTaxesApi');
if (!basketTaxesApi) {
const featureSystemApi = this.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketTaxesApi = storefront.getApiSync('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 (storefront) => {
let basketTaxesApi = storefront.getApiSync('basketTaxesApi');
if (!basketTaxesApi) {
const featureSystemApi = this.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketTaxesApi = storefront.getApiSync('basketTaxesApi');
}
const taxPrices$ = basketTaxesApi.selectSum$();
});