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 out

Methods

MethodParametersDoes
getProgramnoneThe program: how points are earned and the prizes
getPointsnoneThe logged-in customer's points
exchangeprizeId, cartId?, selectedProductId?Spends points on a prize in the cart. Pass selectedProductId when the prize lets the customer choose a product.
resetcartId?Removes the prize from the cart and returns the points
isFeatureEnablednonetrue when the store has the loyalty program on. No request.

Without a cartId, exchange and reset use the current cart.

Events

EventFires whenArguments
loyalty::program.fetched / loyalty::program.not.fetchedgetProgramresponse or error
loyalty::points.fetched / loyalty::points.not.fetchedgetPointsresponse or error
loyalty::exchange.succeeded / loyalty::exchange.failedexchangeresponse or error, prize id
loyalty::exchange-reset.succeeded / loyalty::exchange-reset.failedresetresponse 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, getProgram and getPoints reject at once. Check isFeatureEnabled() first.
  • getPoints rejects for a guest.
  • Old Twig examples listen to these events on Salla.event.rating. They are on Salla.event.loyalty.

See also

On this page