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.
Catalog Agreement Rework (Binding Inversion + Audience-Rule Retirement)
Status: Implemented — phases 1–3 2026-08-30 (binding inversion, resolver + leak fix, audience-rule supersession); phase 4 completed 2026-08-31 (inline price_list payload, agreement editor, products-with-prices view, create wizard, removal warnings). Design finalized 2026-08-30 (extracted from the amendment block in 6.0-b2b-companies-and-catalogs.md, whose Implemented status was hiding this unbuilt work)
Target: Spree 6.0 — sequence Wave 1: everything catalog-shaped builds on the inverted binding, and the leak fix touches unreleased code
Depends on: B2B Companies & Catalogs (6.0-b2b-companies-and-catalogs.md — the shipped catalogs this reworks), PriceList system (released)
Author: Damian + Claude
Last updated: 2026-08-31
Summary
The implementation half of the one-question-per-entity doctrine (decisions.md
2026-08-30): the Catalog becomes the commercial agreement — the one
object answering "what does this buyer see, pay, and buy on" — and the
Catalog ↔ PriceList relationship is reshaped accordingly. The binding
inverts (spree_price_lists.catalog_id replaces
spree_catalogs.price_list_id), which closes a real leak in the shipped
unreleased design; the audience-shaped price rules
(PriceRules::CustomerGroupRule, UserRule) are retired in favor of
catalog assignment; and the dashboard flips to catalog-first, one-go
setup. The related term/pricing features build on this: the quantity
plan's catalog terms (6.0-b2b-quantity-rules.md) and the automatic ±%
pricing card (6.0-price-list-automatic-pricing.md) both land on the
catalog page this rework establishes.
Key Decisions (do not deviate without discussion)
- The binding inverts: a price list is standalone or owned by exactly one
catalog (2026-08-30, interactive review).
spree_price_lists.catalog_id(nullable) replacesspree_catalogs.price_list_id; generic rule matching simply skips owned lists (WHERE catalog_id IS NULL). This closes the leak: the shipped derived exclusion set (Catalog.bound_price_list_ids) reads active catalogs only, so deactivating a catalog dropped its — typically rule-less — list back into generic matching, pricing the whole store. With the FK, a deactivated catalog's list goes dormant. Sharing one list across catalogs is lost — one catalog serving many audiences through assignments is the replacement. - An owned list is never released — removing a catalog's pricing deletes
it (revised 2026-08-30 in review, superseding the detach-with-a-warning
design above). Releasing was to be an explicit act behind a dashboard
warning, but the released state is the dangerous one: an owned list
carries no rules, so back in generic matching it prices every shopper —
the same leak this plan exists to close, reached deliberately instead of
by accident. No warning makes that a reasonable thing to offer, so
price_list: nulland destroying the catalog both destroy the list (has_one ... dependent: :destroy; the model is paranoid, so the prices stay recoverable). Consequences: an owned list never appears in the price-lists index (it has no rules or audience of its own and is edited on its catalog), and switching from fixed prices to a percentage clears the hand-entered amounts, since an explicit row would otherwise keep winning over the adjustment the card claims is in effect. - Audience price rules are grandfathered, not deprecated (revised
2026-08-30 after review — supersedes the same-day "deprecated + data
task" decision).
PriceRules::CustomerGroupRuleandPriceRules::UserRuleduplicated catalog assignment with different, silent precedence, so they are hidden from the rule picker and nothing new builds on them — but they keep matching indefinitely, with no removal date, no creation warning, and no data task. Rationale: the conversion only had to exist because the classes were being removed; once they simply keep working, migrating is churn a merchant gains nothing from, and an automatic remap of who-gets-which-price is exactly the class of change that is dangerous to get wrong. This puts them on the same footing asPriceRules::ChannelRule, already grandfathered for the same reason.MarketRule(carries VAT restatement) andVolumeRuleare context-shaped and stay first-class and offered. - The resolved price and its source ride the catalog's own products
endpoint, behind
expand(2026-08-31, phase 4 review). The nested membership listing answers?expand=catalog_pricewith the amount a buyer on this agreement pays and where it came from — an explicit row on the owned list, the list's ±% adjustment, or the variant's base price. Resolution stays server-side: the dashboard cannot see a derivation that is computed on read and never stored, so inferring the source in React would mean re-implementing the resolver against a shape it cannot observe.expandrather than a bespoke flag, because every other optional payload on this API is asked for the same way. - The catalog's price columns sit on the assortment card, not beside it (2026-08-31). Assortment↔pricing divergence is the thing the view exists to expose, so the price and its source are columns on the rows the merchant already curates — a second list of the same products, or a tab, makes the divergence something to go looking for.
- The transitional
price_list_idaccessors are removed; the inlineprice_listpayload is the only binding (2026-08-31). They existed to keep the admin API's pre-inversion shape working until phase 4 reshaped the payload, which it now has: the catalog serializer dropsprice_list_id, and the model drops the pending-assignment machinery that write path needed. Catalogs are unreleased, so no bridge is owed. - New catalog is a linear four-step wizard, written once at the end (2026-08-31). Details → Audience → Pricing → Review, Back and Next only, with a single create request on Finish carrying the whole agreement. Nothing is written until then, so abandoning midway leaves nothing behind — the same staged-until-Save model the agreement editor uses. The assortment is deliberately not a step: product membership stages against a saved parent through the nested endpoints, and the merchant lands on the agreement editor to curate it.
- Because catalogs are unreleased (6.0 edge), the catalogs side rewrites
in place — the create-catalogs migration drops its
price_list_idreference, no bridge, per the companies-plan precedent. Thespree_price_listsside is a released table and gets an ordinary additive migration forcatalog_id. - The dashboard flips to catalog-first, and setup is one go. The
catalog page becomes the agreement editor — audience assignments,
assortment, an inline pricing card for its owned list, terms — plus a
products-with-prices view showing, per product, assortment membership
and the resolved price with its source (explicit / automatic / base), so
assortment↔pricing divergence is visible instead of
discoverable-by-accident. The New catalog flow takes name, audience,
assortment, and a pricing choice (base prices / ±% adjustment / fixed
prices); the admin catalog create/update endpoints accept an inline
price_listpayload for the owned list, so standing up an agreement never requires visiting the price-lists page.
Design Details
- Associations flip:
PriceList belongs_to :catalog (optional)/Catalog has_one :price_list;Catalog.bound_price_list_idsand itsSpree::Currentmemoization are deleted — the resolver'sapplicable_price_listsfilterscatalog_id: nilin SQL, andcatalog_price_listsreads the association. Only active catalogs still claim their list in the resolution walk (unchanged semantics, now leak-free on the exclusion side). - Supersession is a discovery-level flag, not a bridge:
superseded?on the rule class surfaces assuperseded: truein types discovery (present only when true, so rule families without the concept keep their wire shape), and the dashboard picker filters those kinds out. Existing rules render, edit and match unchanged. - No upgrade step: nothing in the 6.0 manifest touches price rules. A store upgrades with its audience rules matching exactly as before, and adopts catalogs for new agreements at whatever pace suits it.
- Admin API: catalogs create/update accept
price_list: {...}(create or update the owned list inline); the price-lists endpoints keep working for standalone lists;price_list: nullremoves the owned list. - Dashboard: catalog page (agreement editor + products-with-prices view + removal warning), New catalog page. No price-list-page banner for owned lists — they are excluded from that index entirely, since a page offering rules and a schedule describes nothing an owned list has.
Migration Path
- Schema — rewrite the catalogs migration in place (drop
price_list_id); additivecatalog_idonspree_price_lists; edge worktrees rebuild the template DB. Done 2026-08-30 (one live list per catalog is enforced on every adapter — a partial unique index on PostgreSQL/SQLite, a unique index over a stored generated column on MySQL/MariaDB per thespree_commission_ratesprecedent, so the rule never rests on the model validation alone; soft-deleted lists release the slot. The admin API keeps itsprice_list_idread/write shape through model-level accessors over the inverted association until phase 4 reshapes the payload). - Model + resolver — association flip, SQL-level owned-list exclusion,
delete the derived set + memoization; specs pin the leak (a deactivated
catalog's rule-less list prices nobody). Done 2026-08-30 (the
exclusion lives in
PriceList.for_context— the one feed for bothSpree::Current.price_listsand the resolver's direct fetch. Detach and catalog destroy destroy the owned list rather than releasing it —dependent: :destroy, superseding the:nullifythis step originally shipped with, per the revised Key Decision above: an owned list carries no rules, so released it would price every shopper.) - Rule supersession — types-discovery marking only. Done
2026-08-30 (
superseded: trueinsubclasses_with_preference_schema, present only when true so other type-discovery endpoints keep their wire shape; the dashboard rule picker filters those kinds while existing rules still render, edit and match). Deliberately no warnings, no bridge and no data task — see the revised Key Decision above. - API + dashboard — inline
price_listpayload, agreement editor, products-with-prices view, wizard, removal warning. Partly done 2026-08-30: the inline payload (Spree::Catalogs::Create/Updatedelegating toSetPriceList— create, update in place, or remove on an explicit null; a list a catalog owns is named after the catalog and born active, since the catalog's ownactiveflag already gates the agreement) and the agreement editor, where Pricing is its own card (normal prices / ±% / fixed) between Catalog and Audiences. Fixed mode opens the bulk price spreadsheet inline — it is only half-configured until amounts exist. Catalogs gained adescriptionlike price lists, shown in the index; the nav puts Catalogs above Price Lists; and the price-lists index lists standalone lists only. Two warnings state consequences before Save: removing the pricing deletes the list, and switching from fixed to ±% discards the entered amounts. The ±% controls landed with6.0-price-list-automatic-pricing.md. Completed 2026-08-31: the products-with-prices view — the catalog's nested products listing answers?expand=catalog_pricewith the amount a buyer on the agreement pays and its source (explicit/automatic/base), resolved server-side bySpree::Catalogs::ResolvePricesand rendered as price and source columns on the assortment rows, so a product the agreement lists but does not price reads asbasebeside the ones it does; and the create flow, now a linear four-step wizard (Details → Audience → Pricing → Review) writing once on Finish, with the audience editor extracted so the wizard and the agreement editor share one surface. The transitionalCatalog#price_list_idaccessors were removed with it — the inline payload is the only binding. The Terms card arrived with6.0-b2b-quantity-rules.md.
Constraints on Current Work
- No new code reads
spree_catalogs.price_list_idorCatalog.bound_price_list_ids— the FK on the list is the one binding. - No new features build on
PriceRules::CustomerGroupRule/UserRuleorChannelRule(all grandfathered — kept working, hidden from pickers) — audience targeting is catalog assignment; channel pricing is the default catalog. - Catalog-page features (terms, pricing card) mount on the agreement editor this plan establishes — no parallel catalog editing surfaces.
- An owned list's product membership follows the catalog's assortment
—
Catalog#add_products/#remove_productscarry it, and creating an owned list seeds it from what the catalog already holds. Never populate an owned list by another path: the two memberships are separate tables, and a catalog whose list missed the sync shows an empty price spreadsheet while plainly having products. - One list, one formula:
PriceList#derived_price_fromis where an adjustment list's arithmetic lives — the pricing resolver and the catalog's own reading both call it, so the number a merchant is shown and the number a buyer is charged cannot be computed two different ways. Currency rounding goes throughSpree::Money::Rounding, never a localexponentlookup. - Going live is its own act, never a field on a form (2026-09-01). A
catalog is born inactive and reaches buyers through
Spree::Catalogs::Activate— mirroringPriceLists::Activate— so what has to happen alongside (sweeping a buyer's cached catalog set, telling the companies it covers) hangs offafter_activateinstead of being scattered across every caller that flips the flag.activeis absent from the catalog write payload the dashboard sends, so a plain Save can never change whether an agreement applies. Activation is refused for a catalog nobody is assigned to, since it would reach no buyer — the one exception being a channel's default catalog, which is reached through the channel rather than an assignment. - A catalog's resolved price is read through
Spree::Catalogs::ResolvePrices, never re-derived by a client — an adjusted amount is computed on read and never stored, so anything inferring the source from price rows is wrong the moment base prices move. A new surface asking "what does this agreement charge" goes through that service, or thecatalog_priceexpansion over it. - The price spreadsheet reflects staged membership, not just saved
membership — a products card stages its edits until Save, so a grid
opened beside one excludes products staged for removal
(
variant_product_id_not_in) rather than inviting prices that Save discards. Staged additions have no rows to show until Save, so the surface says so instead.
Open Questions
None — the design questions were resolved in the 2026-08-30 entity review (decisions.md). The mixed-rule-list conversion policy (report, don't guess) is deliberate, not open.
References
- decisions.md 2026-08-30 — "One question per entity" (doctrine + rejected alternatives).
docs/plans/6.0-b2b-companies-and-catalogs.md— the shipped catalogs + the amendment block this plan was extracted from.docs/plans/6.0-b2b-quantity-rules.md(terms on this surface),docs/plans/6.0-price-list-automatic-pricing.md(±% card on this surface).- Leak mechanics:
spree/core/app/models/spree/catalog.rb(bound_price_list_ids),spree/core/app/models/spree/pricing_provider/internal.rb(applicable_price_lists).