Charge rules and charge groups: charges added for you
A charge rule adds a charge to a quote or order by itself. Examples:
- freight over a weight;
- a handling fee for a customer class;
- a fee for a small delivery of water.
A charge group names a set of products a rule can count across, such as "water, in cases", whichever SKUs make it up.
Both are the company's own. Nothing is charged until you write the rules and switch them on.
Settings → Charge rules is the screen (/settings/charge-rules). It has
two tabs, Rules and Groups.
-
Opening it needs
charge_group.read; changing anything needscharge_group.manage. -
A rule's condition is chosen from the common shapes:
- every order;
- the order has any of a group;
- fewer than a number of a group;
- weighs more than;
- the goods come to at least (the order's value);
- one customer.
For anything else, choose A condition of your own and write it in JSON.
Switching it on
Set Add charges by rule (sales.order_charges) under Sales settings. It is
off as shipped.
- When it works: while a quote or order is a draft, its rule charges are worked out again each time a line is added, changed or taken off.
- Once confirmed: an order is never re-charged.
- Changing a rule: affects drafts only. It never restates an order already confirmed or an invoice already posted.
Charge groups
A group says which products are in it, and what it is counted in.
| Field | What it does |
|---|---|
| Code | Letters, digits and underscores, such as WATER. Rules name the group by it. |
| Name | What people read, such as "Water (cases)". |
| Collections | Items in these collections, and in the collections inside them unless you say otherwise. |
| Tags, brands, categories | Items with any of these. |
| Items | Items named one by one. |
| Except items, except collections | Taken out even if something above names them. |
| Count in | Each item's own unit (the default) or a packaging unit such as CS. |
| Count each line | Exactly, or rounded up to whole units first. |
| An item with no such packaging | Counts as one of its own unit (the default), or as nothing, with a warning. |
Counting in each item's own unit suits a company that sells only cases: an order's quantity is the case count, and no packaging needs setting up.
Counting in a packaging unit suits a company that sells both bottles and cases. Each line is converted through the item's packaging. 48 bottles of a 24-pack and 36 of a 12-pack count as five cases.
A group that an enabled rule counts cannot be deleted or switched off: switched off, the rule would count nothing and nobody would be told. Change the rule first; its name and notes can still be changed meanwhile. A group's items must be items that exist, and a field the group does not take is refused rather than ignored.
Saving a group or a rule says which: "Charge group “Water (cases)” saved."
Charge rules
Each rule has three parts:
- a condition: when it applies;
- a result: what it charges;
- a priority: lower numbers are read first.
What a condition can read
| Field | What it is |
|---|---|
customer.number, customer.class, customer.group, customer.price_tier, customer.tags | The customer |
customer.payment_terms, customer.freight_terms | Their terms |
customer.freight_charged | Whether their freight terms charge freight on (Freight charged on under Settings → Freight terms). Read this rather than naming terms, so terms you add later are covered |
customer.custom.<key> | Your own customer fields |
ship_to.code, ship_to.route | The delivery location |
ship_to.state, ship_to.postal_code, ship_to.country | Its address |
ship_to.custom.<key> | Your own delivery-location fields |
order.kind | quote or order |
order.channel | Where the order came from (web for a storefront) |
order.store | The store it came through (a storefront's store) |
order.net | The goods' net value |
order.quantity, order.lines | How much, and how many lines |
order.weight | Total weight in kg |
order.ordered_on, order.requested_on | Dates (ISO, so they compare) |
order.payment_terms, order.custom.<key> | The order's terms, and your own order fields |
group.<CODE>.quantity | How many of a group, in its count unit |
group.<CODE>.net, .weight, .lines, .items | The group's net value, weight (kg), lines and distinct items |
group.<CODE>.present | Whether the order has any of it |
The order minimum is never read: a rule charges whether or not the minimum is met.
What a rule charges
| Result field | What it does |
|---|---|
charge_code | The charge code the line is, such as DELIVERY. Its account, tax and billing come from the code. A discount code makes the rule a discount (below). |
method | How the amount is worked out (below). |
amount, percent | The rate. |
group | The group a group method or table reads. |
table, table_on | Steps: [{"up_to": "4", "amount": "20"}, {"up_to": "9", "amount": "10"}, {"up_to": null, "amount": "0"}], read on net, weight, quantity, group_quantity, group_net or group_weight. A step can give a percent of the goods instead of an amount (not both). |
minimum, maximum | Bounds on the amount. |
waive_when_net_at_least | No charge once the goods come to this much. |
service, cheapest_of, markup_percent | For carrier_rate: the carrier service that prices the order, more services to shop for the cheapest (up to nine), and what you add on top. |
slot | Which charge it competes with (below). |
description | What the line says, instead of the code's name. |
| Method | Amount |
|---|---|
flat | amount |
percent_of_net | percent of the goods' net |
per_unit | amount × the order's quantity |
per_line | amount × its goods lines |
per_weight | amount × its weight in kg |
per_group_unit | amount × the group's quantity |
percent_of_group | percent of the group's goods only (mix and match) |
buy_get | Buy X, get Y: for every buy units of the group, get more at get_percent off (a discount code only) |
table | The step the value falls in |
carrier_rate | The service's price for the order's weight from its site to its ship-to address, live where it can be and from its rate table otherwise, plus markup_percent. With cheapest_of, the lowest of the services named |
none | Nothing: the exception rule (below) |
From a carrier's rate table (carrier_rate) prices the order's weight to
its ship-to address from a carrier service you keyed under
Carriers: the zone the address falls in, the weight bracket, the
service's minimum and fuel surcharge, then your markup. A service with a live
rate code is priced by your connected rating service first (EasyPost or
Shippo), and by its table when the live rate cannot be had; see
live rates. Or the
cheapest of names more services, and the order is charged whichever prices it
lowest: rate shopping, done by the rule on every order. The rule preview says
which service was charged and where its price came from ("Live rate from
easypost (USPS Priority)", or "Rate table, as the rating service did not
answer"). Where nothing prices the order, the rule charges nothing and says
why.
A rule naming a charge code or group that does not exist is refused when it is saved, as is a negative amount.
Billed on: once, shared, or every delivery
An order shipped in parts is billed on several invoices. The line a rule adds
is billed as its charge code's Billed on says, unless the rule says
otherwise in Billed on: the first invoice, the one that completes the order,
each invoice its share, each invoice its shipments' actual freight, or every
delivery, in full. With every delivery, the order shows one delivery's
charge, and each invoice bills it once for each shipment it covers: two
shipments on one invoice bill it twice. The order's discount on it is taken
once. In the rule's JSON, "per": "shipment" is the same as
"bill_on": "each_shipment".
Slots: when one rule should override another
- Across slots, charges add up. Freight, fuel and a water fee can all apply to one order.
- Within one slot, the first rule that matches wins, by priority.
- A slot is the rule's own
slot, or else its charge code and group (DELIVERY:WATER).
Writing an exception: add a rule in the same slot, with a smaller priority
number and method none. For "except restaurants", the condition is the
restaurant class.
Discounts by rule
A rule that names a discount code (such as DISCOUNT) takes off the order
instead of adding to it. The line is a discount: it is spread over the goods,
lowers their tax, and posts to Reduces sales revenue. It is worked out again
as the draft changes, like a charge, and comes off when the order no longer
qualifies.
- A threshold: "5% off orders of $2,000 or more" is the shape the goods
come to at least 2000, method
percent_of_net,percent5. - Tiers: "2% from $1,000, 5% from $5,000" is one rule,
tableonnet, each step gives a % of the goods: up to 999.99 → 0, up to 4,999.99 → 2, and above → 5. - A customer group or class, a region, a channel, a product group: any condition a charge rule can read.
- Stacking: two discount rules in one slot do not add up (the first by priority wins: "the best one"). Rules in different slots add up ("loyalty and the spring promotion").
- A discount cannot be priced by a carrier, and it is never billed on one invoice: an order billed in parts gives each invoice its share.
- Telling the buyer: an order short of a discount rule's order-value threshold, or inside a tier with a bigger one above, says so on the desk and in the storefront cart: Add $500.00 more to get $100.00 off.
Buy X, get Y, and mix and match
Both count a charge group, so they work across every product in it: "buy 2 cases of water, get 1 free" holds whether the cases are still or sparkling.
- Buy X, get Y (
buy_get, a discount code only): each set isbuy + getunits of the group, and the cheapest units are the ones given, as a till does. Off the units given is 100 for free, 50 for half price. At most this many sets caps it per order. An order one short of its next set is told: Add 1 more of WATER to get $6.00 off. - A percentage of a group (
percent_of_group): "10% off water once you have 20 cases" is the condition fewer than a number of a group turned round, written asgroup.WATER.quantityat least 20, with this method andpercent10. Only the group's goods are discounted.
Recipes
| You want | How |
|---|---|
| A fee on every delivery of water, even when the minimum is met | Group WATER. Rule: group.WATER.present is true → DELIVERY, flat, $10 |
| $1.50 per case of water | Same group, counted in CS. Rule: per_group_unit, $1.50 |
| Fewer than 5 cases of water → $20 | Rule: group.WATER.quantity > 0 and < 5 → SMALL_ORDER, flat, $20 |
| 1–4 cases $20, 5–9 $10, 10 or more free | One rule, table on group_quantity |
| …except one customer, or restaurants | A rule with a smaller priority number, in slot DELIVERY:WATER, method none |
| Freight over 500 kg | order.weight > 500 → FREIGHT, per_weight |
| Free freight over $500 | waive_when_net_at_least: 500 |
| 5% off orders of $2,000 or more | Goods at least 2000 → DISCOUNT, percent_of_net, 5 |
| 2% from $1,000, 5% from $5,000 | DISCOUNT, table on net, steps by % of goods |
| Buy 2 cases of water, get 1 free | Group WATER. DISCOUNT, buy_get, buy 2, get 1 |
| Third case half price, once per order | buy_get, buy 2, get 1, off the units given 50, at most 1 set |
| 10% off water from 20 cases | group.WATER.quantity ≥ 20 → DISCOUNT, percent_of_group, 10 |
| $50 off a wholesale customer's first order of the month | A condition of your own, → DISCOUNT, flat, 50 |
On the order
A rule's charge is a line of its own, named by the rule:
- "Delivery: 5 CS x 1.50" for a per-case charge;
- the code's name otherwise.
Changing or taking it off needs sales_order.charge_override and a
reason, and is audited. From then on:
- a changed line is the person's, and is not worked out again;
- a removed one is not added back.
Recalculate charges, on the order desk, forgets those changes and works the charges out afresh. The desk also says how to avoid a charge, such as "Add 2 more of WATER to save $20.00 on SMALL_ORDER", for codes shown to buyers.
Try the rules on an order: GET /api/v1/sales/orders/{id}/charges returns:
- each rule: whether it matched, and why;
- the group counts it saw;
- the charge it would add;
- "add 2 more cases to avoid the $20 fee" hints, for codes shown to buyers.
It writes nothing.
On the storefront
A signed-in buyer whose business has an account with you sees your rule charges in the cart and at review:
- each charge whose code is shown to buyers by name, under that company's part of the cart, in its total;
- how to avoid one: "Add 3 more of WATER to save $20.00".
The order they place carries the same charges, because it is built the same way. Codes not shown to buyers are still charged on the order; they are just not named in the cart.
Moving a storefront's delivery fee into the rules. Commerce → Storefronts → Companies has Move fee to charge rules beside a company that charges a delivery fee there. It:
- adds a rule Delivery on storefront to that company's charge rules:
- this storefront's web orders (
order.channeliswebandorder.storeis its store) are chargedDELIVERYat the fee; - the order is free from the "waived over" amount, if there is one;
- this storefront's web orders (
- switches the company's Add charges by rule on;
- clears the storefront's own fee, so delivery is charged once.
From then on, change the fee under Settings → Charge rules, like any other charge. If you add a delivery rule by hand instead, clear the storefront's own fee yourself. Otherwise both are charged.
Who can do what
| Permission | Roles | Allows |
|---|---|---|
charge_group.read | Manager, Sales, Accounting | See the groups and rules |
charge_group.manage | Manager | Add and change groups and rules |
sales_order.charge_override | Manager, Sales | Change or take off a rule's charge on an order, with a reason |