loyalty
Read the store's loyalty program and the customer's points, and exchange points for a prize in the cart.
Use Salla.loyalty when the store runs a loyalty program: customers collect points and spend them on prizes in the cart.
The loyalty API module reads the same data for a page, and the salla-loyalty web component shows the whole program: see salla-loyalty.
const { data: program } = await Salla.loyalty.getProgram();
await Salla.loyalty.exchange(978); // spend points on prize 978 in the current cart
await Salla.loyalty.reset(); // take the prize back outMethods
| Method | Parameters | Does |
|---|---|---|
getProgram | none | The program: how points are earned and the prizes |
getPoints | none | The logged-in customer's points |
exchange | prizeId, cartId?, selectedProductId? | Spends points on a prize in the cart. Pass selectedProductId when the prize lets the customer choose a product. |
reset | cartId? | Removes the prize from the cart and returns the points |
isFeatureEnabled | none | true when the store has the loyalty program on. No request. |
Without a cartId, exchange and reset use the current cart.
Events
| Event | Fires when | Arguments |
|---|---|---|
loyalty::program.fetched / loyalty::program.not.fetched | getProgram | response or error |
loyalty::points.fetched / loyalty::points.not.fetched | getPoints | response or error |
loyalty::exchange.succeeded / loyalty::exchange.failed | exchange | response or error, prize id |
loyalty::exchange-reset.succeeded / loyalty::exchange-reset.failed | reset | response or error |
A successful exchange or reset also fires cart::updated, so your cart summary updates by itself.
Gotchas
- On a store without the loyalty program,
getProgramandgetPointsreject at once. CheckisFeatureEnabled()first. getPointsrejects for a guest.- Old Twig examples listen to these events on
Salla.event.rating. They are onSalla.event.loyalty.