Price lists#
A price list holds a price per SKU in one currency, either including or excluding VAT (is_included_vat). Lists are linked at three levels:
| Linked to | How | Purpose |
|---|---|---|
| Channel | The channel's pricing settings: one list per currency. | The default prices. Sets the cart's currency and VAT mode. |
| Organisation | price_list_id on createOrganisation / updateOrganisation, or when approving it with approveOrganisation. | Prices for everyone who orders for this business. |
| Contact | price_list_id on createContact / updateContact. | Prices for one person. |
How the cart picks a price#
- When the cart is created, it takes the channel list for its currency:
currencyfromcreateCart, or the channel's default currency. That list sets whether the cart is including VAT (cart.is_including_vat). A currency without a list on the channel can't be used. - When a contact or organisation is added to the cart, their lists are added to the channel list.
- For every SKU the cart looks at all those lists and takes the lowest price. The highest becomes
original_amount, so the customer sees the discount. - A SKU that isn't on a customer's list keeps its price from the other lists.
So a customer list gives a customer better prices; it never makes a SKU more expensive than the channel list. cart.price_lists shows the lists the cart prices with: the channel list first, then those of the organisation and the contact. The cart doesn't show which list a single price came from.
Give customer lists the same VAT mode as the channel list. Whether the cart is including VAT always follows the channel list, also when a customer list is added.
Loading the prices into the cart#
To charge a logged-in customer their own prices, add the customer to the cart. Use the ids from the user token: sub is the contact, organisation_id the organisation when they act for one. With a storefront token, also send the user token itself as customer.user_token, so Afosto can check that the ids belong to the customer who is logged in.
A user_token that doesn't belong to the contact, the organisation or the channel is refused.
When the contact or organisation has a price list, Afosto reprices every item already in the cart and returns the new totals. Items you add afterwards get the customer's prices straight away. Prices that were set by hand on an item stay as they are.
For a new cart you can pass the customer to createCart right away:
Add the customer again after logInAsOrganisation or logOutAsOrganisation, so the cart follows the organisation the customer acts for.
When the customer goes to the hosted checkout while logged in on the shared domain, the checkout adds them to the cart itself. Adding them in the storefront as well means the cart page already shows the right prices.
Showing the prices on product pages#
The cart only prices what is in it. To show a logged-in customer their prices on product and list pages, read account.prices with the user token. It returns the price per SKU that the cart would charge, with the tiers of the list that applies. A SKU without a price is left out.
amount and original_amount are in cents. Whether they include VAT follows the channel list, like cart.is_including_vat.