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.
Channel-Scoped Delivery (Channel → Stock Locations)
Status: Implemented (PR #14404)
Target: Spree 6.0
Depends on: 6.0-delivery-profiles.md (profiles + origin groups, shipped in PR #14404), 6.0-order-routing.md (Channel, preferred_stock_location_id on Order), 6.0-channel-markets.md (sibling axis, composes)
Author: Damian Legawiec + Claude (design session 2026-08-09)
Last updated: 2026-08-09
Summary
Let a Channel be limited to a subset of the store's stock locations, constraining which fulfillment origins serve its traffic — and therefore which delivery options its carts are quoted. Today Channel and the delivery model are fully orthogonal: a wholesale channel's cart is quoted from every origin group of the product's profile, and nothing can express "the B2B channel ships only from the wholesale warehouse" or "the POS channel fulfills only from its own store". The link is an optional allowlist join (spree_channel_stock_locations, empty = all locations — today's behavior), enforced on the origin axis the delivery model already filters on: allocation and quoting simply intersect an origin group's effective locations with the channel's served set.
This is the industry's shape for the problem. The delivery-profiles work deliberately keeps profiles channel-free (a profile answers "how do these products ship", not "who is buying"); the platform that models both — Medusa — links sales channels to stock locations, never to shipping profiles, and lets channel-appropriate delivery options fall out transitively through the origin. Without this plan, the only way to express channel-specific delivery in Spree is a separate profile per channel with products duplicated across them — exactly the duplication origin groups were built to kill.
Key Decisions (do not deviate without discussion)
- The channel links to stock locations, not to profiles and not to origin groups (2026-08-09). Profiles group products; groups partition origins; the channel constrains which origins serve its traffic. Linking channel→profile would fork the catalog per channel; linking channel→group would make groups do double duty and duplicate a relationship the channel already needs for inventory. Origin is the one axis where the concern actually lives — and it is the axis the Coordinator and Estimator already filter on, so enforcement is an intersection, not a new mechanism.
- Empty allowlist = every location — the established "no rows means no restriction" convention (
6.0-channel-markets.md, origin-group members, method service rows). Existing stores upgrade with zero behavior change. - Origin scoping is origin-side filtering, never method-side rules. Using a rule to decide which warehouses serve a channel was considered and rejected: a method could be visible while its origins cannot serve the channel, quoting rates that allocation then contradicts. The stock-location allowlist keeps quoting and allocation consistent by construction.
- Rate visibility IS a method-side rule (2026-08-10). The separate question — which delivery options and prices a channel is offered from origins it already reaches — is
Spree::DeliveryMethodRules::ChannelRule, an STI rule beside ItemTotal/Weight/ExcludedProducts, enforced in the Estimator's method filter. This is what makes "wholesale pays €5, retail pays €10, same warehouse, same goods" expressible without duplicating products or profiles; a differing price is a second method carrying the rule, exactly as zones already work. The two mechanisms answer different questions and compose: origins decide whether a channel can be served, rules decide what it is offered. - Pickup follows the same rule: a channel's carts only see pickup counters among the channel's served locations. No special casing —
available_pickup_locationsintersects like everything else. - Order routing is unchanged.
preferred_stock_location_idlives on the Order (customer pickup selection / routing outcome), and its resolution path already scopes bypickup_enabled— the channel intersection lands in that same resolution. The allowlist constrains the candidate set; routing strategies order within it.
Design Details
Model
spree_channel_stock_locations (join; unique [channel_id, stock_location_id])
Channel has_many :channel_stock_locations, :stock_locations (through)
Channel#serves_location?(stock_location) # empty allowlist → true
Channel#served_stock_locations # empty → store.stock_locations
Enforcement points (all one predicate)
- Allocation —
Stock::Coordinatoralready asksprofile.covers_location?; it additionally askschannel.serves_location?when the cart has a channel. Items allocate only from origins both the profile's groups and the channel serve. Orders go through the same check, sinceOrderRouting::Strategy::Rulespacks through the Coordinator (2026-10-26; before, an order's allocation skipped both). - Quoting —
Stock::Estimator's method filter already consultsserves_location?(package.stock_location); a package sourced from a non-served location never exists (filtered at allocation), so quoting needs no extra check — documented as invariant, covered by spec. - Pickup discovery — the store
pickup_locationsendpoint andCarts::Update'spreferred_stock_location_idresolution intersect with the cart's channel. - Pickup selection —
Carts::Updateresolves the customer'spreferred_stock_location_idthroughpickup_enabledAND the cart channel's served set, so a non-served counter 404s exactly like a non-pickup one.
API / Dashboard
- Admin API:
stock_location_idson the channel serializer + params (replace-set, empty = all) — same shape as origin groups. - Dashboard: a "Fulfillment locations" card on the channel form (
all/selectedradio + checkbox list, the exact pattern shipped for origin groups and profiles). - Store API: no new surface — the constraint manifests as which delivery options and pickup counters a channel-bound cart sees.
Migration Path
Additive only: one create_table migration for the join. No backfill (empty = all preserves behavior). No deprecations.
Constraints on Current Work
- New code resolving fulfillment origins for a cart must flow through the profile/group coverage path (
covers_location?/fulfillable_stock_locations) so the channel intersection lands in one place — never enumeratestore.stock_locationsdirectly in delivery code. - Don't add channel awareness to DeliveryProfile, DeliveryOriginGroup, or DeliveryMethod — the channel constraint composes from outside.
Open Questions
In-PR vs follow-up— resolved 2026-08-09 (Damian): implemented inside PR #14404, same pattern as origin groups.- Whether
Order#channel_idis reliably present on carts at quoting time in all storefront paths (key-bound channel vs. explicit header) — a nil channel means unrestricted, which is safe; audited during implementation for the primary paths.
References
6.0-delivery-profiles.md(origin groups — the axis this composes with)6.0-channel-markets.md(sibling allowlist: markets axis; together: "wholesale channel → EU markets, wholesale warehouse")6.0-order-routing.md(Channel model,preferred_stock_location_id)- Medusa's sales-channel ↔ stock-location link (the transitive-delivery precedent; competitor names in plans only)