Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Record what the commission survey found
Damian Legawiec1961b03fd0dd
diff --git a/docs/plans/6.0-multi-vendor-marketplace.md b/docs/plans/6.0-multi-vendor-marketplace.mdindex 86454e1af9..776ce58724 100644--- a/docs/plans/6.0-multi-vendor-marketplace.md+++ b/docs/plans/6.0-multi-vendor-marketplace.md@@ -54,6 +54,7 @@ Mirror the core insight from both the legacy module and the industry references:- New model **`Spree::CommissionLine`** (NOT a revival of the legacy commission table, NOT a polymorphic `Adjustment`). One row per commissioned line item — plus one per fulfillment when the rate commissions delivery revenue (`include_shipping`, Decision 4) — storing a **snapshot** of `rate`, `amount`, and the resolved rule's identity.- Written by a service during/after `cart.complete!`, once. A later rate change does not touch existing lines.+- **Frozen, not re-derived (corroborated 2026-08-17).** A source review of the leading surveyed OSS engine found it re-resolves commission from *current* rate configuration on every refresh (order edit, return received, claim created), deleting and reinserting the lines — so editing a rate there retroactively changes what a seller was already charged on past orders. Its own documentation claims the opposite, which is worth knowing if it is ever used as a reference. Ours are a snapshot written once, the same rule the duties work settled ("never re-derive from the live catalog on an existing order").- **Commission is NOT a `Spree::Fee`.** `6.0-6.1-split-adjustments.md`'s `Fee` is a *buyer-facing* charge — it rolls into `order.fee_total` and the order total the customer pays. Commission is a *platform ↔ vendor* settlement line the customer never sees; it must never touch order totals. `CommissionLine` is therefore its own off-order ledger table that merely follows the same typed-line design (concrete FKs, no polymorphic source, no state machine) as the split-adjustments family. The only real split-adjustments dependency is that tax lines / discounts / fees are line-item-attached, so they re-home cleanly to the child order during the split. (A *buyer-facing* marketplace service fee — StockX-style — would be a `Spree::Fee` with a `kind`; possible later, out of scope here.)### 3. Commission taxation is a first-class field — this is the OSS differentiator@@ -63,6 +64,10 @@ This is the one place where the **legacy Enterprise module is ahead of the surve- `tax_amount` — VAT/tax **on that commission**, at a configurable commission tax rate,- `total` — `amount + tax_amount`.+**One tax or several? (OPEN, raised 2026-08-17.)** We model the fee's tax as a single `tax_amount` + `rate` pair on the line. The enterprise platform surveyed ships exactly that shape as **deprecated**: its scalar `commission_vat`/`commission_rate_vat` are superseded by a `commission_taxes[]` array of `{code, rate, amount}`, because the scalars can only return "the first tax applied" where several apply at once. Its `total_commission` is then defined as fee + the summed tax. Its taxability is also a per-seller property (`applicable_taxes[]` bound to fee types), which matches our resolution against the vendor's billing address.++A scalar is right for a single-VAT supply, which is the EU case this plan is built for, and it is what the legacy module did. It is wrong wherever a fee attracts two levies at once. Deciding now is cheap — nothing has shipped — and expensive later, since widening a scalar to a collection changes the ledger's shape and every reader of it. Flagged rather than resolved: the fee-VAT itself is the headline feature and works today; this is about whether the *container* is a number or a list.+**EU base (RESOLVED 2026-06-25):** commission is computed on the seller's **net (ex-VAT)** item price, and `tax_amount` is applied **on top of the commission** — the marketplace fee is a separate taxable supply from the consumer's item sale, so the two VATs never mix. That base toggle stays available for non-EU/edge merchants who want a gross base (shipped as `tax_inclusive`), but the EU default is net-base + fee-VAT. The **tax-on-the-fee** field is mandatory and is the headline EU feature. The commission tax *rate* is resolved through `6.0-tax-provider.md` (per-Market TaxProvider) rather than a bare `platform_fee_tax_rate` column on the vendor (RESOLVED — see Resolved Decisions).### 4. Commission rate resolution: layered rules, first match wins in operator order — generalize the legacy flat rate@@ -73,6 +78,12 @@ The legacy module resolves a **single flat percentage** with a two-level fallbac**Rule matching is dimension-grouped: AND across dimensions, OR within a dimension.** A rate's rules are grouped by subject type (Product / Taxon / Vendor); the rate matches a line item when *every* dimension group present has at least one matching rule. `{taxon: Electronics, taxon: Cameras, vendor: X}` reads "(Electronics OR Cameras) AND vendor X" — which expresses plain lists *and* the **vendor × category pairing** today's Enterprise sells (user docs: "per vendor, per category-vendor pairing, or per individual product") with no `match_policy` knob at all. The leading surveyed OSS engine uses the same semantics, so the model is proven; where we differ deliberately is precedence — an explicit operator-ordered list instead of implicit most-specific-wins, which is more predictable (already RESOLVED below).+**Rule shape evidence (survey 2026-08-17).** Read against the enterprise platform's own published API contract, our `(subject_type, subject_id)` rule is the weakest of the three models surveyed. There, a rule carries a typed configuration block — seller ids, channel codes, brands, condition codes — plus a validity `period` and an applicability ceiling, and its rate is a list of tiered thresholds rather than one number. Every dimension we currently cannot express without a migration (price band, channel, validity window, product attribute) is a field there. The other OSS engine shares our shape and is equally stuck: five hardcoded dimensions behind a `switch` with no extension point, and it removed its own minimum-amount cap rather than generalising it. The conclusion is that a commission rule needs **its own configuration**, not merely a pointer to a record — which is what the STI rule pattern already used by `Spree::PriceRule` and `Spree::DeliveryMethodRule` provides (see Resolved Decisions).++Two specifics worth copying rather than inventing. Tiering is expressed as thresholds carrying only a lower bound, so bands are contiguous by construction and can neither overlap nor leave a gap — safer than storing min/max pairs and validating the relationship. And precedence there is likewise an explicit operator-declared ranking (a per-category ordered list), not inferred specificity: both surveyed platforms independently concluded the merchant must be able to state which rule wins.++**Precedence evidence (source review 2026-08-17).** That engine is worth reading on this point because it has now tried *both* of the alternatives we rejected. It shipped a `priority` integer, then dropped it in a later migration in favour of most-specific-wins — scoring a rate by how many distinct dimensions it names, tie-broken by creation date. Two failure modes follow from that scoring and are visible in its current source: dimensions are unranked, so a product-specific rate and a seller-wide rate both score 1 and the *older* one wins; and creation order therefore becomes load-bearing configuration a merchant can neither see nor change. Our ordered list is the third option and answers both — the ladder is explicit, visible, and reorderable. The same review found that engine also removed its `min_amount` cap, and has no notion of tax on the commission at all, so our floor/cap and the EU fee-VAT have no prior art there to copy.+**`include_shipping` on the rate** (default `false`): when the resolved rate has it, the same calculation also runs against the vendor order's delivery amounts, persisting a fulfillment-scoped `CommissionLine`. The surveyed OSS competitor commissions shipping via a global-rate-only flag, and Amazon-style referral fees include it; the legacy module was items-only (its order-level "reverse fee" only prorates *item* commission on whole-order refunds — shipping is excluded from its base). Ours is per-rate — strictly more flexible than a global-only flag, and off by default so legacy behavior is preserved.**Precedence (RESOLVED 2026-06-25; reshaped 2026-08-17 — `acts_as_list`, shipped): an ordered list, not a fixed ladder.** Rates carry `position` via `acts_as_list scope: :store_id` and are walked top-down, first match wins — so the order an operator sees in the table *is* the precedence, and reordering is dragging a row rather than reasoning about an integer. **New rates are created at the top** (`add_new_at: :top`): a rate exists to say something more specific than what is already there, and appending would file it behind the catch-all that matches everything. Seeds put a disabled marketplace-wide rate at the bottom, which makes the product-then-category-then-seller order merchants asked for fall out for free without hardcoding it. Ordering is deliberately **not** derived from how specific a rate's rules look: a rate may name a product, a category and a seller at once, so there is no single dimension to sort on, and "narrowest wins" guesses at an intent the operator can simply state.