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.
Draft Order Negotiation Mechanics (Manual Line Pricing + Cart Copy)
Status: Implemented — full 6.0 scope built 2026-08-30 (manual pricing + guards + reserved key, created_by, docstring fix, Orders::CreateFromCart, dashboard editable price; the payment-number search fixes from 6.0-6.1-b2b-payment-terms.md rode along per the Wave 1 bundling)
Target: Spree 6.0 (retargeted 2026-08-30: the cart→draft copy moved from 6.1 into 6.0 so the Enterprise quotes product needs nothing beyond 6.0 GA)
Depends on: Cart/Order split (6.0-cart-order-split.md), Third-Party Pricing (6.0-third-party-pricing-inventory.md — price_source), Service Workflows (6.0-service-workflows.md)
Author: Damian + Claude
Last updated: 2026-08-30
Summary
Draft orders (staff-created Spree::Order rows, status: 'draft',
cart_id: nil) already carry most of a negotiation engine: items,
addresses, manual fees and discounts that survive recalculation and freeze
at placement, notes, and invoice-later conversion. What's missing is the
one thing every negotiated B2B deal needs — setting a unit price ("10,000
units @ $7.20 for this order only, without touching the customer's price
list") — plus the machinery to start a negotiation from a customer's cart
without consuming it. This plan ships those open-source mechanics; the
customer-facing quotation product (lifecycle, send/accept, expiry, portal)
is Enterprise (ee/docs/plans/b2b-quotes.md; tier split
decided 2026-08-30 — same shape as company registration: OSS mechanisms,
Enterprise flow). Manual pricing is deliberately 6.0: it polishes the
brand-new draft-order surface (phone orders need it too) and rides with two
fixes in the same area; the copy service lands late in 6.0 so its Enterprise
consumer (quotes) needs nothing beyond 6.0 GA (retargeted 2026-08-30).
Key Decisions (do not deviate without discussion)
price_source: 'manual'is the negotiated-price marker (2026-08-30): the existing write-only provenance column gains its first reader. Setting a line's price through the admin API stamps'manual'; the two repricing paths gain guards —Carts::PriceItemsskips manual rows, andLineItem#should_update_price?answers false for them — so a quantity change no longer silently re-prices a negotiated line from the pricing provider.'manual'is a reserved key: no pricing provider may register it.- Explicit revert, never silent.
price: nullon the item update is the "back to catalog price" gesture — clears the marker and re-prices through the resolver. Nothing else may overwrite a manual price. - Price overrides are pre-placement only. Once placed, money edits stay what they are today — fees and discounts — until the 6.1 order-change substrate owns post-placement amendments. Overrides answer "what is the agreed unit price", discounts answer "what concession is itemized on top"; both freeze at placement through the existing paths.
price_sourceis admin-only surface. Exposed on the admin line-item serializer (the dashboard marks negotiated lines and offers the revert); never on the store serializer — provenance is operational.Orders::Createstampscreated_by(bug fix): the column and association exist but were never written, leaving staff drafts identifiable only bycart_id IS NULL.- The
payment_pendingdocstring is corrected (bug fix): it promisespayment_status: 'balance_due', but the status rollup has no such branch and produces'none'. The docstring now tells the truth; whether an unpaid placed order deserves a distinct rollup value is decided inside the wholesale-deposit work (6.0-b2b-wholesale-shipping.mdphase 7), which is already reshaping that rollup — not here, and not twice. Spree::Orders::CreateFromCart(6.0, late) copies a customer's cart into a fresh draft order — line items with prices andprice_sourceas they stand, addresses, customer/company, notes, metadata — leaving the cart untouched (a buyer who requests a quote keeps shopping). No money records, no fulfillments: those are rebuilt by the draft's own lifecycle. Deliberately a new service, not a reuse ofCarts::Complete's private copy helpers — that copy re-points money records and is one-shot by unique index; this one is an independent duplicate.
Design Details
Manual pricing (6.0)
- Admin surface:
priceaccepted onPOST/PATCH /admin/orders/:id/items(and the inlineitems:list on order create);Orders::UpdateItemgains aprice:keyword. Guarded to incomplete orders. - Model: setting a price through these paths assigns
price_source: 'manual'. Guards:
# Carts::PriceItems#call — before resolving a row:
next if line_item.price_source == 'manual'
# LineItem#should_update_price?
!owner.completed? && price_source != 'manual'
- Dashboard: the draft-order items table's unit price becomes an editable input; a negotiated line shows a marker + "reset to catalog price" action; the order create form keeps quantity-only (override on the edit page, where the resolved price is visible to compare against).
- Specs pin the contract: a manual price survives quantity changes,
recalculation, an external-pricing store's
confirm_prices, and placement; revert re-prices; a provider registering key'manual'raises.
Fixes (6.0)
created_by stamped from the authenticated admin in Orders::Create;
payment_pending docstring corrected to payment_status: 'none' with the
cross-reference to the deposit rollup work.
Cart → draft order copy (6.0, late)
Spree::Orders::CreateFromCart.call(cart:, created_by: nil, customer: nil)
→ draft Spree::Order (no cart_id — it is NOT the completion copy and
must not claim the one-shot slot). Consumers: the Enterprise
request-a-quote flow (buyer-initiated), and plain admin "start a draft from
this cart".
Migration Path
- 6.0 — guards + admin
priceparams +'manual'stamping + reserved key;created_by; docstring fix; dashboard editable price; admin serializerprice_source. Implemented 2026-08-30. - 6.0, late —
Orders::CreateFromCart+ specs; consumed by the Enterprise quote plan. Implemented 2026-08-30 (pulled forward — it is small and independent; registered asSpree.order_create_from_cart_service, no admin endpoint yet — its consumers are the Enterprise quote flow and host code).
Implementation notes (2026-08-30): the manual marker's canonical constant is
Spree::PricingProvider::MANUAL_PRICE_SOURCE (aliased as
Spree::LineItem::MANUAL_PRICE_SOURCE) — deliberately on the lightweight
provider module, because the boot-time reserved-key check
(Spree::PricingProvider.verify_registry!, run from the engine's
after_initialize) must not force the model graph to load early (it
measurably reorders Preferable#defined_preferences, which reads methods
order). The row-level guard lives in BOTH halves of
Spree::Carts::PriceItems — #call skips manual rows before asking the
provider, and .apply refuses to write onto one — because probe-based flows
(AddItem, UpsertItems) resolve against stand-ins and only meet the real row
at the write. The upsert item price is tri-state (absent / amount / null)
end to end: Carts::ResolvedItem#price_provided, the dashboard payload
builder, and Orders::UpdateItem's PRICE_NOT_PROVIDED sentinel.
Stamping created_by surfaced a latent serializer bug: the admin order
serializer rendered its three staff actors (created_by, approver,
canceler — all Spree.admin_user_class) through the CUSTOMER serializer,
which 500s on phone the moment the association is populated; they now go
through admin_admin_user_serializer (the OpenAPI refs moved
Customer → AdminUser accordingly).
Editor preview (2026-08-30, from live UI review). Staged edits are shown
as a before/after diff — the saved figure struck through beside the new one —
on the unit price, the line total, the subtotal AND the grand total. Two
constraints shape it. The admin line-item serializer gained catalog_price
(the variant's BASE price, so a revert can preview what it restores and a
negotiated line can be read against the price it replaced): deliberately not a
resolved price, because resolving would consult the pricing provider once per
row on a read path that must stay provider-free — it is a comparison figure,
not a promise, since the revert re-prices through the resolver and may land on
a price-list amount. It forced eager-loading line_items: { variant: :prices }
in the orders controller's scope (which bypasses scope_includes), taking
the order page from 15 price queries to 1. And the grand total previews only
when every other total line is zero: shipping, tax, discounts and fees are
recomputed from rules the browser cannot evaluate (a quantity change can cross
a shipping band or promotion threshold), so adding a subtotal delta onto the
old total would state a confidently wrong number — but on a plain draft the
total IS the subtotal, and freezing it there was the more confusing lie. A row
whose price cannot be projected (a revert with no catalog price) makes the
whole projection null rather than contributing a partial sum.
No data migration; every existing line has a provider or nil
price_source and behaves exactly as today.
Constraints on Current Work
- Nothing may reprice a
price_source: 'manual'line except the explicit revert; any new repricing call site must honor the guard. 'manual'never becomes a pricing-provider key.- No post-placement price overrides — placed-order money edits remain fees/discounts until the order-change substrate.
- Store serializers never expose
price_source. - Quote lifecycle, statuses, expiry, customer surfaces: Enterprise plan — don't grow them here.
Open Questions
None for this scope. (Whether unpaid placed orders get a distinct payment-status value is owned by the wholesale-deposit rollup work.)
References
- Merchant feedback, 2026-08 (extend draft orders into quotations; negotiated line-item pricing that must not touch the price list).
- Tier split:
docs/plans/decisions.md2026-08-30;ee/docs/plans/b2b-quotes.md(the flow). - Repricing contract:
spree/core/app/services/spree/carts/price_items.rb,spree/core/app/models/spree/line_item.rb(should_update_price?,update_adjustments). - Draft-order path:
spree/core/app/services/spree/orders/create.rb,app/workflows/spree/orders/complete.rb(payment_pending),app/workflows/spree/carts/complete.rb(complete_draft_order).