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 toHowPurpose
ChannelThe channel's pricing settings: one list per currency.The default prices. Sets the cart's currency and VAT mode.
Organisationprice_list_id on createOrganisation / updateOrganisation, or when approving it with approveOrganisation.Prices for everyone who orders for this business.
Contactprice_list_id on createContact / updateContact.Prices for one person.

How the cart picks a price#

  1. When the cart is created, it takes the channel list for its currency: currency from createCart, 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.
  2. When a contact or organisation is added to the cart, their lists are added to the channel list.
  3. 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.
  4. 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.

ℹ
Tip:

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.

mutation AddCustomer($input: AddCustomerToCartInput!) {
  addCustomerToCart(input: $input) {
    cart {
      id
      customer {
        contact {
          id
        }
        organisation {
          id
        }
      }
      items {
        sku
        quantity
        total
      }
      total
    }
  }
}
{
  "input": {
    "cart_id": "72fca344-2a6f-4c3e-b4ca-029920b2522a",
    "customer": {
      "contact_id": "3c6f4a8e-1b2d-4e5f-8a9b-0c1d2e3f4a5b",
      "organisation_id": "9e8d7c6b-5a4f-4e3d-2c1b-0a9f8e7d6c5b",
      "user_token": "eyJhbGciOiJSUzI1NiIs…"
    }
  }
}

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:

{
  "input": {
    "customer": {
      "contact_id": "3c6f4a8e-1b2d-4e5f-8a9b-0c1d2e3f4a5b",
      "organisation_id": "9e8d7c6b-5a4f-4e3d-2c1b-0a9f8e7d6c5b",
      "user_token": "eyJhbGciOiJSUzI1NiIs…"
    }
  }
}

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.

query AccountPrices($skus: [String!]!, $currency: Currency) {
  account {
    prices(skus: $skus, currency: $currency) {
      sku
      amount
      original_amount
      vat {
        rate
        country_code
      }
      tiers {
        min_quantity
        amount
        is_percentage
      }
    }
  }
}
{ "skus": ["BLK-HOODIE-M", "BLK-HOODIE-L"], "currency": "EUR" }

amount and original_amount are in cents. Whether they include VAT follows the channel list, like cart.is_including_vat.

Query Runnerhttps://afosto.app/graphql

No query loaded

Click play on any code block in the docs to load a query here.