Basket Loyalty API¶
Feature name: basket
Api name: basketLoyaltyApi
API used to perform actions regarding a basket loyalty section like: - retrieving the amount of awarded loyalty points - retrieving a number of items that the client paid for with loyalty points - retrieving a total cost in loyalty points
classDiagram
direction LR
class selectLoyaltyPointsAwarded["selectLoyaltyPointsAwarded$"]
class selectHasItemsPaidInLoyaltyPoints["selectHasItemsPaidInLoyaltyPoints$"]
class selectLoyaltyPointsCost["selectLoyaltyPointsCost$"]
class selectLoyaltyPointsExchangePrice["selectLoyaltyPointsExchangePrice$"]
BasketLoyaltyAPI --> selectLoyaltyPointsAwarded
BasketLoyaltyAPI --> getLoyaltyPointsAwarded
BasketLoyaltyAPI --> selectHasItemsPaidInLoyaltyPoints
BasketLoyaltyAPI --> getHasItemsPaidInLoyaltyPoints
BasketLoyaltyAPI --> selectLoyaltyPointsCost
BasketLoyaltyAPI --> getLoyaltyPointsCost
BasketLoyaltyAPI --> selectLoyaltyPointsExchangePrice
BasketLoyaltyAPI --> getLoyaltyPointsExchangePrice
class BasketLoyaltyAPI {
selectLoyaltyPointsAwarded$(): Observable~LoyaltyPoints|null~
getLoyaltyPointsAwarded(): LoyaltyPoints|null
selectHasItemsPaidInLoyaltyPoints$(): Observable~boolean~
getHasItemsPaidInLoyaltyPoints(): boolean
selectLoyaltyPointsCost$(): Observable~LoyaltyPoints|null~
getLoyaltyPointsCost(): LoyaltyPoints|null
selectLoyaltyPointsExchangePrice$(): Observable~FullPrice|null~
getLoyaltyPointsExchangePrice(): FullPrice|null
}
link selectLoyaltyPointsAwarded "../methods/select-loyalty-points-awarded/"
link getLoyaltyPointsAwarded "../methods/get-loyalty-points-awarded/"
link selectHasItemsPaidInLoyaltyPoints "../methods/select-has-items-paid-in-loyalty-points/"
link getHasItemsPaidInLoyaltyPoints "../methods/get-has-items-paid-in-loyalty-points/"
link selectLoyaltyPointsCost "../methods/select-loyalty-points-cost/"
link getLoyaltyPointsCost "../methods/get-loyalty-points-cost/"
link selectLoyaltyPointsExchangePrice "../methods/select-loyalty-points-exchange-price/"
link getLoyaltyPointsExchangePrice "../methods/get-loyalty-points-exchange-price/"
Get API¶
To get the Basket Loyalty API
use its name basketLoyaltyApi
with the getApiSync
method.
useStorefront(async (storefront) => {
const basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
});
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 = storefront.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
const basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
});
Methods¶
- selectLoyaltyPointsAwarded$ - select the amount of awarded loyalty points
- getLoyaltyPointsAwarded - retrieve the amount of awarded loyalty points
- selectHasItemsPaidInLoyaltyPoints$ - select whether items paid for using loyalty points are present in the basket or not
- getHasItemsPaidInLoyaltyPoints - retrieve whether items paid for using loyalty points are present in the basket or not
- selectLoyaltyPointsCost$ - select a cost of exchanged items in points
- getLoyaltyPointsCost - retrieve a cost of exchanged items in points
- selectLoyaltyPointsExchangePrice$ - select a price of exchanged items
- getLoyaltyPointsExchangePrice - retrieve a price of exchanged items
Example¶
In this example we make a basketLoyaltyApi
call to retrieve whether items paid for using loyalty points are present in the current basket or not.
useStorefront(async (storefront) => {
let basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
if (!basketLoyaltyApi) {
const featureSystemApi = storefront.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
}
const hasItemsPaidInLoyaltyPoints = basketLoyaltyApi.getHasItemsPaidInLoyaltyPoints();
if (hasItemsPaidInLoyaltyPoints) {
console.log('There are some products exchanged with loyalty points');
}
else {
console.log('Products exchanged with loyalty points not found');
}
});
Example¶
In this example we make a basketLoyaltyApi
call to select the cost of exchanged items in points
useStorefront(async (storefront) => {
let basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
if (!basketLoyaltyApi) {
const featureSystemApi = storefront.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
}
const loyaltyPointsCost$ = basketLoyaltyApi.selectLoyaltyPointsCost$();
loyaltyPointsCost$.subscribe((loyaltyPointsCost) => {
console.log('The cost of items exchanged in a loyalty program: ', loyaltyPointsCost);
});
});
Example¶
In this example we make a basketLoyaltyApi
call to select the amount of awarded loyalty points.
useStorefront(async (storefront) => {
let basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
if (!basketLoyaltyApi) {
const featureSystemApi = storefront.getApiSync('FeatureSystemApi');
await featureSystemApi.registerDynamic('basket');
basketLoyaltyApi = storefront.getApiSync('basketLoyaltyApi');
}
const loyaltyPointsAwarded$ = basketLoyaltyApi.selectLoyaltyPointsAwarded$();
loyaltyPointsAwarded$.subscribe((loyaltyPoints) => {
console.log('The amount of awarded points: ', loyaltyPoints);
});
});