Skip to main content

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 needs charge_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.

FieldWhat it does
CodeLetters, digits and underscores, such as WATER. Rules name the group by it.
NameWhat people read, such as "Water (cases)".
CollectionsItems in these collections, and in the collections inside them unless you say otherwise.
Tags, brands, categoriesItems with any of these.
ItemsItems named one by one.
Except items, except collectionsTaken out even if something above names them.
Count inEach item's own unit (the default) or a packaging unit such as CS.
Count each lineExactly, or rounded up to whole units first.
An item with no such packagingCounts 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​

FieldWhat it is
customer.number, customer.class, customer.group, customer.price_tier, customer.tagsThe customer
customer.payment_terms, customer.freight_termsTheir terms
customer.freight_chargedWhether 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.routeThe delivery location
ship_to.state, ship_to.postal_code, ship_to.countryIts address
ship_to.custom.<key>Your own delivery-location fields
order.kindquote or order
order.channelWhere the order came from (web for a storefront)
order.storeThe store it came through (a storefront's store)
order.netThe goods' net value
order.quantity, order.linesHow much, and how many lines
order.weightTotal weight in kg
order.ordered_on, order.requested_onDates (ISO, so they compare)
order.payment_terms, order.custom.<key>The order's terms, and your own order fields
group.<CODE>.quantityHow many of a group, in its count unit
group.<CODE>.net, .weight, .lines, .itemsThe group's net value, weight (kg), lines and distinct items
group.<CODE>.presentWhether 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 fieldWhat it does
charge_codeThe 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).
methodHow the amount is worked out (below).
amount, percentThe rate.
groupThe group a group method or table reads.
table, table_onSteps: [{"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, maximumBounds on the amount.
waive_when_net_at_leastNo charge once the goods come to this much.
service, cheapest_of, markup_percentFor 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.
slotWhich charge it competes with (below).
descriptionWhat the line says, instead of the code's name.
MethodAmount
flatamount
percent_of_netpercent of the goods' net
per_unitamount × the order's quantity
per_lineamount × its goods lines
per_weightamount × its weight in kg
per_group_unitamount × the group's quantity
percent_of_grouppercent of the group's goods only (mix and match)
buy_getBuy X, get Y: for every buy units of the group, get more at get_percent off (a discount code only)
tableThe step the value falls in
carrier_rateThe 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
noneNothing: 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, percent 5.
  • Tiers: "2% from $1,000, 5% from $5,000" is one rule, table on net, 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 is buy + get units 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 as group.WATER.quantity at least 20, with this method and percent 10. Only the group's goods are discounted.

Recipes​

You wantHow
A fee on every delivery of water, even when the minimum is metGroup WATER. Rule: group.WATER.present is true → DELIVERY, flat, $10
$1.50 per case of waterSame group, counted in CS. Rule: per_group_unit, $1.50
Fewer than 5 cases of water → $20Rule: group.WATER.quantity > 0 and < 5 → SMALL_ORDER, flat, $20
1–4 cases $20, 5–9 $10, 10 or more freeOne rule, table on group_quantity
…except one customer, or restaurantsA rule with a smaller priority number, in slot DELIVERY:WATER, method none
Freight over 500 kgorder.weight > 500 → FREIGHT, per_weight
Free freight over $500waive_when_net_at_least: 500
5% off orders of $2,000 or moreGoods at least 2000 → DISCOUNT, percent_of_net, 5
2% from $1,000, 5% from $5,000DISCOUNT, table on net, steps by % of goods
Buy 2 cases of water, get 1 freeGroup WATER. DISCOUNT, buy_get, buy 2, get 1
Third case half price, once per orderbuy_get, buy 2, get 1, off the units given 50, at most 1 set
10% off water from 20 casesgroup.WATER.quantity ≥ 20 → DISCOUNT, percent_of_group, 10
$50 off a wholesale customer's first order of the monthA 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:

  1. adds a rule Delivery on storefront to that company's charge rules:
    • this storefront's web orders (order.channel is web and order.store is its store) are charged DELIVERY at the fee;
    • the order is free from the "waived over" amount, if there is one;
  2. switches the company's Add charges by rule on;
  3. 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​

PermissionRolesAllows
charge_group.readManager, Sales, AccountingSee the groups and rules
charge_group.manageManagerAdd and change groups and rules
sales_order.charge_overrideManager, SalesChange or take off a rule's charge on an order, with a reason