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
Publish cart lifecycle events
Damian Legawiece3474d62d4c1
diff --git a/docs/plans/6.0-cart-order-split.md b/docs/plans/6.0-cart-order-split.mdindex 11d4d3cab4..74298339e2 100644--- a/docs/plans/6.0-cart-order-split.md+++ b/docs/plans/6.0-cart-order-split.md@@ -67,6 +67,7 @@ Every competitor treats this as load-bearing. `Spree::Carts::Complete`:- Cancel/resume/approve remain services (`Orders::Cancel`/`Resume`/`Approve` — approve is already machine-free) flipping `status` and running today's side effects (restock/void/refund branches preserved verbatim). `awaiting_return`/`returned` states are **not** carried over — that lifecycle belongs to `6.0-returns-exchanges-claims.md`'s first-class Return models.- The `confirmation_required?` self-reference (the `|| confirm?` hack from #4117) dies with the machine: whether the confirm/review step exists is computed **from data only** (`Spree::Config[:always_include_confirm_step]` or any selected payment method requiring confirmation). A confirm-stage failure no longer "falls back" to an earlier state — there are no states; the client stays on review with the failure in `requirements`/errors.- Order `state_changes` audit rows are dropped in favor of lifecycle events (`order.placed`, `order.canceled`, `order.resumed`, `order.approved` — already published today). Payment/fulfillment machines keep their own `StateChange` rows.+- **Event naming after the split (settled 2026-07-29):** carts publish their own `cart.created` / `cart.updated` / `cart.deleted` lifecycle events (restoring the 5.x abandonment signal that incomplete orders' `order.*` events used to provide; Shopify `carts/*` parity). `order.completed` stays the placement event — `order.created` cannot take that role because it fires for every order row, including admin drafts and the pre-payment draft copy inside `Carts::Complete` (a failed payment then emits `order.deleted` for it). Renaming would also break every 5.x webhook consumer and the emails/metrics subscribers for no semantic gain.- **Price-freeze guarantee** (what OSS platform C's `ArrangingPayment` lock provided): `completing_at` rejects cart mutations while payment is in flight, and the completed Order is immutable per split-adjustments' order-level freeze. Auditable price-at-completion also serves EU Omnibus.### 7. Cart hygiene — new, and newly necessarydiff --git a/spree/core/app/models/spree/cart.rb b/spree/core/app/models/spree/cart.rbindex cd76c42336..0ee07f416f 100644--- a/spree/core/app/models/spree/cart.rb+++ b/spree/core/app/models/spree/cart.rb@@ -11,6 +11,11 @@ module Spreeclass Cart < Spree.base_classhas_prefix_id :cart+ # cart.created / cart.updated / cart.deleted — the abandonment-tooling+ # signal (parity with 5.x, where incomplete orders emitted order.*).+ # Payload serializes through the V3 cart serializer by convention.+ publishes_lifecycle_events+has_secure_token# Concurrency is manual (the API's OrderLock semantics — comparediff --git a/spree/core/spec/models/spree/cart_spec.rb b/spree/core/spec/models/spree/cart_spec.rbindex 0c560a639b..4078235e31 100644--- a/spree/core/spec/models/spree/cart_spec.rb+++ b/spree/core/spec/models/spree/cart_spec.rb@@ -1,6 +1,24 @@require 'spec_helper'describe Spree::Cart, type: :model do+ describe 'lifecycle events' do+ it 'publishes cart.* lifecycle events' do+ expect(described_class.lifecycle_events_enabled).to be true+ expect(described_class.event_prefix).to eq('cart')++ registered = described_class._commit_callbacks.map(&:filter)+ expect(registered).to include(:publish_create_event, :publish_update_event, :publish_delete_event)+ end++ # The V3 cart serializer resolves by convention when spree_api is loaded;+ # core's dummy app only sees the fallback payload.+ it 'carries the prefixed id in the event payload' do+ cart = create(:cart, store: @default_store)++ expect(cart.event_payload[:id]).to eq(cart.prefixed_id)+ end+ end+describe 'readonly after completion' dolet(:cart) { create(:cart, store: @default_store) }