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
Show the operator which seller sold an order, and what it was bought with
Damian Legawiecbaebfa36fa6f
diff --git a/docs/plans/6.0-multi-vendor-marketplace.md b/docs/plans/6.0-multi-vendor-marketplace.mdindex 052d7bfe2d..01fdaa20f6 100644--- a/docs/plans/6.0-multi-vendor-marketplace.md+++ b/docs/plans/6.0-multi-vendor-marketplace.md@@ -700,7 +700,7 @@ This is **new OSS code**, not a rename of existing core — there is no in-place- **Phase 3a — fund ledger (next).** The two-level `SellerTransfer` (on-fulfillment) + `SellerPayout` (scheduled sweep) + `PayoutProvider::System` + `seller.balance(currency)`. Sequenced after the split because the transfer basis is `child_order.total − commission_lines.sum(:total)`, which needs child orders and their captured shares to exist.- **Note for the second splitting consumer (recorded 2026-08-20).** `Carts::SplitBySeller` is seller-specific in exactly **three lines** — the `seller_id` stamped on the adopted order and on each sibling, and the `line_items.where(seller_id:)` that selects a partition's rows. Everything else (group construction, number suffixing, parcel division and its delivery-cost apportionment, typed-line re-homing, order-level fee proration, the `resum_only` re-total) is partition-agnostic. When split-by-location or B2B split-by-company-location lands, the move is to lift those three lines into a registered splitter (`Spree.order_splitters`, following `Spree.stock_splitters`/`Spree.adjusters`) and rename the rest to `Orders::Split`, **not** to copy the file. Deliberately not done now, per the standing rule that a flow generalizes when it has a second consumer rather than speculatively — but the analysis is recorded so the second consumer does not have to redo it.- **Phase 3b — OSS Stripe provider** (after Phase 3, alongside the Stripe gateway pull-in: the payment-sessions-API gateway classes come into the monorepo from the standalone `spree_stripe` repo, likely into `spree/core`, leaving the legacy v2-API/storefront code behind): Express onboarding link in the seller dashboard, `account.updated` status webhook, `transfer!` on fulfillment with `source_transaction`, payout-schedule mapping + payout webhooks. Ledger-only `reverse!`.- - **Phase 4 — Dashboards.** (a) Operator marketplace screens in `@spree/dashboard`: Sellers list/detail (lifecycle actions, branding, commission + payout settings, ledger-derived lifetime revenue/commission), Commission Rates settings page, Payouts review queue (owed balances, itemized payouts, mark-paid), OrderGroup rendering on order screens, and a "needs attention" queue on the dashboard home (sellers `ready_for_review` + pending seller products — a lightweight unified review inbox). (b) Seller panel: compose `@spree/dashboard-ui` + `@spree/dashboard-core` into a seller-scoped panel (per `6.0-admin-spa.md` — the package split exists precisely for this) talking to the Seller API branch (own login page + `seller_api` tokens; `PermissionProvider` fed by `/seller/me`). Seller roles come from the operator's roles editor filtered to the seller audience; the operator's Sellers detail screen assigns them. Surfaces the seller's products, orders + fulfillment actions, and the balance + transfer/payout ledger (earned/settled) read-only for OSS.+ - **Phase 4 — Dashboards.** **The order surfaces landed early with Phase 3 (2026-08-21)**, since a split checkout is unreadable without them: the orders table gained optional `seller` and `order_group` columns (both `default: false`, so a store selling only its own goods never sees them) with Ransack filters behind them, and the order page gained a marketplace card naming the seller — linked to their profile — and, when the order was one of several, the purchase it belonged to with a link back to the list filtered to its siblings. The card renders nothing on an ordinary order. Deliberately **no order-group screen of its own**: the group is the shared payment and the identity of the purchase, and what an operator acts on is always an order, so the group appears as a filter and a link rather than a page. `orders.seller_id`/`order_group_id` joined the Ransack allowlist (without which a filter silently matches nothing); the serializer carries **ids only**, with the seller's name coming from `?expand=seller` requested by the column while it is visible — a denormalized `seller_name` was tried and dropped as a second copy of something the association already answers. The order group is deliberately **not** expandable from an order: its serializer renders the orders it holds, so expanding it from one of them would render that order inside itself, and a client wanting the group has `/order_groups/:id`. Remaining: (a) Operator marketplace screens in `@spree/dashboard`: Sellers list/detail (lifecycle actions, branding, commission + payout settings, ledger-derived lifetime revenue/commission), Commission Rates settings page, Payouts review queue (owed balances, itemized payouts, mark-paid), OrderGroup rendering on order screens, and a "needs attention" queue on the dashboard home (sellers `ready_for_review` + pending seller products — a lightweight unified review inbox). (b) Seller panel: compose `@spree/dashboard-ui` + `@spree/dashboard-core` into a seller-scoped panel (per `6.0-admin-spa.md` — the package split exists precisely for this) talking to the Seller API branch (own login page + `seller_api` tokens; `PermissionProvider` fed by `/seller/me`). Seller roles come from the operator's roles editor filtered to the seller audience; the operator's Sellers detail screen assigns them. Surfaces the seller's products, orders + fulfillment actions, and the balance + transfer/payout ledger (earned/settled) read-only for OSS.**Phases 1–2 have no dependency on the Cart/Order split** — they can be built (even shipped behind a preview flag in a 5.x release) while the split refactor lands, de-risking the 6.0 timeline.diff --git a/packages/admin-sdk/src/types/generated/Order.ts b/packages/admin-sdk/src/types/generated/Order.tsindex f5a679de56..9a3f83e676 100644--- a/packages/admin-sdk/src/types/generated/Order.ts+++ b/packages/admin-sdk/src/types/generated/Order.ts@@ -1,7 +1,7 @@-// Typelizer digest a858835c532b24ee10b21ddfb4d9ae8f+// Typelizer digest 1e527c82d4587146ab589172e40c5271//// DO NOT MODIFY: This file was automatically generated by Typelizer.-import type {LineItem, Fulfillment, Payment, Address, GiftCard, Market, AppliedPromotion, Cart, Channel, StockLocation, PaymentMethod, Customer, Return, Exchange, Claim} from '@/types'+import type {LineItem, Fulfillment, Payment, Address, GiftCard, Market, Seller, AppliedPromotion, Cart, Channel, StockLocation, PaymentMethod, Customer, Return, Exchange, Claim} from '@/types'interface Order {id: string;@@ -64,6 +64,9 @@ interface Order {updated_at: string;preferred_stock_location_id: string | null;company_location_id: string | null;+ seller_id: string | null;+ seller?: Seller;+ order_group_id: string | null;company_id: string | null;tags: Array<string>;internal_note: string | null;diff --git a/packages/dashboard/src/components/spree/orders/order-marketplace-card.tsx b/packages/dashboard/src/components/spree/orders/order-marketplace-card.tsxnew file mode 100644index 0000000000..4aaf14bbc9--- /dev/null+++ b/packages/dashboard/src/components/spree/orders/order-marketplace-card.tsx@@ -0,0 +1,65 @@+import type { Order } from '@spree/admin-sdk'+import { Card, CardContent, CardHeader, CardTitle } from '@spree/dashboard-ui'+import { Link } from '@tanstack/react-router'+import { StoreIcon } from 'lucide-react'+import { useTranslation } from 'react-i18next'+import { useSeller } from '../../../hooks/use-sellers'+import { orderGroupSearch } from '../../../lib/order-group-search'++/**+ * Where this order sits in the marketplace: who sold it, and — when the+ * customer's basket spanned several sellers — that it was part of a larger+ * purchase.+ *+ * Renders nothing for an ordinary order, so a store that sells only its own+ * goods never sees it.+ */+export function MarketplaceCard({ order }: { order: Order }) {+ const { t } = useTranslation()+ const { data: seller } = useSeller(order.seller_id ?? undefined)++ if (!order.seller_id && !order.order_group_id) return null++ return (+ <Card>+ <CardHeader>+ <CardTitle>{t('admin.orders.detail.section_seller')}</CardTitle>+ </CardHeader>+ <CardContent className="flex flex-col gap-3 text-sm">+ {order.seller_id ? (+ <div className="flex items-center gap-2">+ <StoreIcon className="size-4 shrink-0 text-muted-foreground" />+ <Link+ to={'/$storeId/sellers/$sellerId' as string}+ params={{ sellerId: order.seller_id }}+ className="no-underline"+ >+ {seller?.name ?? order.seller_id}+ </Link>+ </div>+ ) : (+ <div className="flex items-center gap-2 text-muted-foreground">+ <StoreIcon className="size-4 shrink-0" />+ {t('admin.fields.order.seller.first_party')}+ </div>+ )}++ {order.order_group_id && (+ <div className="flex flex-col gap-1 border-t pt-3">+ <span>{t('admin.orders.detail.order_group_part_of')}</span>+ <span className="text-xs text-muted-foreground">+ {t('admin.orders.detail.order_group_help')}+ </span>+ <Link+ to={'/$storeId/orders' as string}+ search={orderGroupSearch(order.order_group_id)}+ className="text-sm"+ >+ {t('admin.orders.detail.order_group_view_all')}+ </Link>+ </div>+ )}+ </CardContent>+ </Card>+ )+}diff --git a/packages/dashboard/src/lib/order-group-search.test.ts b/packages/dashboard/src/lib/order-group-search.test.tsnew file mode 100644index 0000000000..47cdea928f--- /dev/null+++ b/packages/dashboard/src/lib/order-group-search.test.ts@@ -0,0 +1,24 @@+import { describe, expect, it } from 'vitest'+import { orderGroupSearch } from './order-group-search'++describe('orderGroupSearch', () => {+ it('encodes the filter the way the resource table reads it back', () => {+ const search = orderGroupSearch('ogrp_abc123')++ expect(JSON.parse(search.filters)).toEqual([+ { id: 'order-group-ogrp_abc123', field: 'order_group', operator: 'eq', value: 'ogrp_abc123' },+ ])+ })++ // The table maps the `order_group` column onto the order_group_id Ransack+ // attribute, so the rule names the column rather than the attribute.+ it('names the column, which is what the table resolves filters by', () => {+ const [rule] = JSON.parse(orderGroupSearch('ogrp_abc123').filters)++ expect(rule.field).toBe('order_group')+ })++ it('leaves the visible columns alone', () => {+ expect(orderGroupSearch('ogrp_abc123')).not.toHaveProperty('columns')+ })+})diff --git a/packages/dashboard/src/lib/order-group-search.ts b/packages/dashboard/src/lib/order-group-search.tsnew file mode 100644index 0000000000..e1c7d3fd7f--- /dev/null+++ b/packages/dashboard/src/lib/order-group-search.ts@@ -0,0 +1,24 @@+/**+ * Search params that open the orders list showing one purchase's orders.+ *+ * A basket spanning several sellers becomes several orders, and the thing an+ * operator wants from any one of them is the rest — so both the orders table+ * and the order page link here rather than each spelling the filter out.+ *+ * The rule is JSON-encoded because that is how the resource table reads+ * filters back off the URL. Columns are deliberately left alone: the `columns`+ * param replaces the whole visible set, so naming any here would hide whatever+ * the operator had chosen.+ *+ * @param orderGroupId prefixed id of the group, as the API reports it+ */+export function orderGroupSearch(orderGroupId: string): { filters: string } {+ const rule = {+ id: `order-group-${orderGroupId}`,+ field: 'order_group',+ operator: 'eq',+ value: orderGroupId,+ }++ return { filters: JSON.stringify([rule]) }+}diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.jsonindex 574be901f4..84b92c4526 100644--- a/packages/dashboard/src/locales/ar.json+++ b/packages/dashboard/src/locales/ar.json@@ -1132,6 +1132,14 @@},"internal_note": {"label": "ملاحظة داخلية (للموظفين فقط)"+ },+ "order_group": {+ "label": "عملية الشراء",+ "view": "عرض عملية الشراء"+ },+ "seller": {+ "label": "البائع",+ "first_party": "تبيعه بنفسك"}},"payment_method": {@@ -2296,6 +2304,9 @@"voided": "تم إلغاء الدفع"},"no_customer": "لا توجد معلومات العميل",+ "order_group_help": "تم تقديم هذا الطلب مع طلبات أخرى في عملية دفع واحدة.",+ "order_group_part_of": "جزء من عملية شراء أكبر",+ "order_group_view_all": "عرض كل الطلبات في عملية الشراء هذه","payment_form": {"amount_help": "اتركه فارغًا لتقصير الرصيد المستحق.","capture_immediately": "التقط على الفور",@@ -2315,6 +2326,7 @@},"section_customer_note": "Special Instructions","section_internal_note": "Internal Note",+ "section_seller": "البائع","summary": {"adjustments": "التعديلات","approved_by": "تمت الموافقة عليه من قبل",diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.jsonindex 9cd8f67c1c..8686258a81 100644--- a/packages/dashboard/src/locales/de.json+++ b/packages/dashboard/src/locales/de.json@@ -1117,6 +1117,14 @@},"internal_note": {"label": "Interne Notiz (nur Mitarbeiter)"+ },+ "order_group": {+ "label": "Einkauf",+ "view": "Einkauf anzeigen"+ },+ "seller": {+ "label": "Verkäufer",+ "first_party": "Eigener Verkauf"}},"payment_method": {@@ -2282,6 +2290,9 @@"voided": "Zahlung storniert"},"no_customer": "Keine Kundeninformationen",+ "order_group_help": "Diese Bestellung wurde zusammen mit anderen in einem Checkout aufgegeben.",+ "order_group_part_of": "Teil eines größeren Einkaufs",+ "order_group_view_all": "Alle Bestellungen dieses Einkaufs anzeigen","payment_form": {"amount_help": "Leer lassen, um standardmäßig den offenen Saldo zu verwenden.","capture_immediately": "Sofort einziehen",@@ -2301,6 +2312,7 @@},"section_customer_note": "Besondere Anweisungen","section_internal_note": "Interne Notiz",+ "section_seller": "Verkäufer","summary": {"adjustments": "Anpassungen","approved_by": "Genehmigt von",diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex 3c7be23e86..e71093ebc3 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -1117,6 +1117,14 @@},"internal_note": {"label": "Internal note (staff only)"+ },+ "order_group": {+ "label": "Purchase",+ "view": "View purchase"+ },+ "seller": {+ "label": "Seller",+ "first_party": "Sold by you"}},"payment_method": {@@ -2282,6 +2290,9 @@"voided": "Payment voided"},"no_customer": "No customer information",+ "order_group_help": "This order was placed alongside others in one checkout.",+ "order_group_part_of": "Part of a larger purchase",+ "order_group_view_all": "View all orders in this purchase","payment_form": {"amount_help": "Leave blank to default to the outstanding balance.","capture_immediately": "Capture immediately",@@ -2301,6 +2312,7 @@},"section_customer_note": "Special Instructions","section_internal_note": "Internal Note",+ "section_seller": "Seller","summary": {"adjustments": "Adjustments","approved_by": "Approved by",diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.jsonindex c764bab3f5..83493918d4 100644--- a/packages/dashboard/src/locales/fr.json+++ b/packages/dashboard/src/locales/fr.json@@ -1117,6 +1117,14 @@},"internal_note": {"label": "Note interne (personnel uniquement)"+ },+ "order_group": {+ "label": "Achat",+ "view": "Voir l'achat"+ },+ "seller": {+ "label": "Vendeur",+ "first_party": "Vendu par vous"}},"payment_method": {@@ -2282,6 +2290,9 @@"voided": "Paiement annulé"},"no_customer": "Aucune information client",+ "order_group_help": "Cette commande a été passée avec d’autres lors d’un même paiement.",+ "order_group_part_of": "Fait partie d'un achat plus large",+ "order_group_view_all": "Voir toutes les commandes de cet achat","payment_form": {"amount_help": "Laissez vide pour utiliser par défaut le solde restant dû.","capture_immediately": "Capturer immédiatement",@@ -2301,6 +2312,7 @@},"section_customer_note": "Instructions spéciales","section_internal_note": "Note interne",+ "section_seller": "Vendeur","summary": {"adjustments": "Ajustements","approved_by": "Approuvé par",diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.jsonindex d0db24f9d0..7d516b578c 100644--- a/packages/dashboard/src/locales/pl.json+++ b/packages/dashboard/src/locales/pl.json@@ -1133,6 +1133,14 @@},"internal_note": {"label": "Notatka wewnętrzna (tylko dla personelu)"+ },+ "order_group": {+ "label": "Zakup",+ "view": "Zobacz zakup"+ },+ "seller": {+ "label": "Sprzedawca",+ "first_party": "Sprzedajesz Ty"}},"payment_method": {@@ -2302,6 +2310,9 @@"voided": "Płatność unieważniona"},"no_customer": "Brak informacji o kliencie",+ "order_group_help": "To zamówienie zostało złożone razem z innymi w jednym zamówieniu.",+ "order_group_part_of": "Część większego zakupu",+ "order_group_view_all": "Zobacz wszystkie zamówienia z tego zakupu","payment_form": {"amount_help": "Pozostaw puste, aby użyć domyślnie pozostałego salda.","capture_immediately": "Pobierz natychmiast",@@ -2321,6 +2332,7 @@},"section_customer_note": "Specjalne instrukcje","section_internal_note": "Notatka wewnętrzna",+ "section_seller": "Sprzedawca","summary": {"adjustments": "Korekty","approved_by": "Zatwierdzone przez",diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.jsonindex 4806fdcc07..556559a7e1 100644--- a/packages/dashboard/src/locales/zh-CN.json+++ b/packages/dashboard/src/locales/zh-CN.json@@ -1114,6 +1114,14 @@},"internal_note": {"label": "内部备注(仅员工可见)"+ },+ "order_group": {+ "label": "本次购买",+ "view": "查看本次购买"+ },+ "seller": {+ "label": "卖家",+ "first_party": "自营"}},"payment_method": {@@ -2278,6 +2286,9 @@"voided": "付款已作废"},"no_customer": "无客户信息",+ "order_group_help": "该订单与其他订单在同一次结账中下单。",+ "order_group_part_of": "属于一次更大的购买",+ "order_group_view_all": "查看本次购买的所有订单","payment_form": {"amount_help": "留空则默认为未结清的余额。","capture_immediately": "立即扣款",@@ -2297,6 +2308,7 @@},"section_customer_note": "特别说明","section_internal_note": "内部备注",+ "section_seller": "卖家","summary": {"adjustments": "调整","approved_by": "审批人",diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/index.tsxindex ec1632017c..1105525886 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/index.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId/index.tsx@@ -20,6 +20,7 @@ import {import { CustomerCard } from '../../../../../components/spree/orders/order-customer-card'import { DiscountsCard } from '../../../../../components/spree/orders/order-discounts-sidebar-card'import { OrderHeader } from '../../../../../components/spree/orders/order-header'+import { MarketplaceCard } from '../../../../../components/spree/orders/order-marketplace-card'import {InternalNoteCard,SpecialInstructionsCard,@@ -84,6 +85,7 @@ function OrderDetailPage() {sidebar={<><CustomerCard order={order} />+ <MarketplaceCard order={order} /><TagsCard order={order} /><DiscountsCard order={order} /><SpecialInstructionsCard order={order} />diff --git a/packages/dashboard/src/tables/orders.tsx b/packages/dashboard/src/tables/orders.tsxindex 3397d7298b..9c57c238e3 100644--- a/packages/dashboard/src/tables/orders.tsx+++ b/packages/dashboard/src/tables/orders.tsx@@ -4,6 +4,8 @@ import { Link } from '@tanstack/react-router'import i18n from 'i18next'import { ShoppingCartIcon } from 'lucide-react'import { channelAutocompleteProps } from '../hooks/use-channels'+import { sellerAutocompleteProps } from '../hooks/use-sellers'+import { orderGroupSearch } from '../lib/order-group-search'/*** Localized label for an order status code, resolved from the given namespace@@ -148,6 +150,57 @@ defineTable('orders', {default: false,render: (order) => order.currency ?? '—',},+ // Only meaningful on a marketplace: an order for the operator's own goods+ // has no seller, so the cell says so rather than reading blank.+ {+ key: 'seller',+ label: i18n.t('admin.fields.order.seller.label'),+ filterable: true,+ filterType: 'resource',+ filterResource: sellerAutocompleteProps('orders-table-seller-filter'),+ ransackAttribute: 'seller_id',+ // Requested only while the column is on — ResourceTable unions the+ // expands of visible columns into the list request.+ expand: 'seller',+ default: false,+ render: (order) =>+ order.seller_id ? (+ <Link+ to={'/$storeId/sellers/$sellerId' as string}+ params={{ sellerId: order.seller_id }}+ className="no-underline"+ >+ {order.seller?.name ?? order.seller_id}+ </Link>+ ) : (+ <span className="text-muted-foreground">+ {i18n.t('admin.fields.order.seller.first_party')}+ </span>+ ),+ },+ // Which purchase this order was part of, when a basket spanning several+ // sellers became several orders. Clicking it narrows the list to that+ // purchase's orders.+ {+ key: 'order_group',+ label: i18n.t('admin.fields.order.order_group.label'),+ filterable: true,+ ransackAttribute: 'order_group_id',+ default: false,+ className: 'text-sm text-muted-foreground',+ render: (order) =>+ order.order_group_id ? (+ <Link+ to={'/$storeId/orders' as string}+ search={orderGroupSearch(order.order_group_id)}+ className="no-underline"+ >+ {i18n.t('admin.fields.order.order_group.view')}+ </Link>+ ) : (+ '—'+ ),+ },{key: 'status',label: i18n.t('admin.fields.status.label'),diff --git a/spree/api/app/controllers/spree/api/v3/admin/orders_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/orders_controller.rbindex 4bd81d60a3..6b82761511 100644--- a/spree/api/app/controllers/spree/api/v3/admin/orders_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/orders_controller.rb@@ -137,8 +137,11 @@ module Spreeauthorize!(mapped_action, resource)end+ # seller is preloaded because its id is read on every row and an+ # expanded list renders the whole profile; order_group is not, since+ # only its id is reported and that comes off the order's own column.def collection_includes- [:line_items, :customer, :channel]+ [:line_items, :customer, :channel, :seller]endprivatediff --git a/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rbindex ab20951f3d..47089bd1bc 100644--- a/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/order_serializer.rb@@ -7,7 +7,9 @@ module Spreeclass OrderSerializer < V3::OrderSerializertypelize company_location_id: [:string, nullable: true],- company_id: [:string, nullable: true]+ company_id: [:string, nullable: true],+ seller_id: [:string, nullable: true],+ order_group_id: [:string, nullable: true]# The Admin API has no guest gating — money fields inherited from the# store serializer are always present, so override their nullability.@@ -56,6 +58,27 @@ module Spreeorder.company_location&.prefixed_idend+ # Whose sale this is — nil on the operator's own goods. The full+ # profile is `?expand=seller`.+ attribute :seller_id do |order|+ order.seller&.prefixed_id+ end++ one :seller,+ resource: proc { Spree.api.admin_seller_serializer },+ if: proc { expand?('seller') }++ # The checkout this order was placed in, when it was placed alongside+ # others.+ #+ # Deliberately an id and no expand: the group serializer renders the+ # orders it holds, so expanding it from an order would render this+ # order again inside itself. A client wanting the group fetches+ # /order_groups/:id, which is what that endpoint is for.+ attribute :order_group_id do |order|+ Spree::OrderGroup.prefixed_id_for(order.order_group_id)+ end+attribute :company_id do |order|order.company_location&.company&.prefixed_idenddiff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders_marketplace_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders_marketplace_spec.rbnew file mode 100644index 0000000000..baa7a44afc--- /dev/null+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders_marketplace_spec.rb@@ -0,0 +1,89 @@+require 'spec_helper'++# What an operator needs from the orders list once a checkout can divide:+# which seller a row belongs to, which purchase it was part of, and the+# ability to narrow to either.+RSpec.describe Spree::Api::V3::Admin::OrdersController, 'marketplace columns and filters', type: :controller do+ render_views++ include_context 'API v3 Admin authenticated'++ let(:seller) { create(:seller, :approved, store: store, name: 'Sparks Audio') }+ let(:other_seller) { create(:seller, :approved, store: store, name: 'Quill Books') }+ let(:group) { create(:order_group, store: store) }++ let!(:seller_order) do+ create(:order, store: store, order_group: group, seller: seller, status: 'placed', completed_at: Time.current)+ end+ let!(:first_party_order) do+ create(:order, store: store, order_group: group, status: 'placed', completed_at: Time.current)+ end+ let!(:unrelated_order) do+ create(:order, store: store, seller: other_seller, status: 'placed', completed_at: Time.current)+ end++ before { request.headers.merge!(headers) }++ def rows+ json_response['data']+ end++ def row_for(order)+ rows.find { |row| row['number'] == order.number }+ end++ describe 'GET #index' do+ it 'names the seller on each row' do+ get :index, as: :json++ expect(row_for(seller_order)['seller_id']).to eq(seller.prefixed_id)+ end++ it 'carries the whole profile when asked to expand it' do+ get :index, params: { expand: 'seller' }, as: :json++ expect(row_for(seller_order)['seller']['name']).to eq('Sparks Audio')+ end++ it 'leaves the operator’s own order without a seller' do+ get :index, as: :json++ expect(row_for(first_party_order)['seller_id']).to be_nil+ expect(row_for(first_party_order)['seller']).to be_nil+ end++ it 'names the purchase a row was part of' do+ get :index, as: :json++ expect(row_for(seller_order)['order_group_id']).to eq(group.prefixed_id)+ end++ it 'leaves an ungrouped order without a purchase' do+ get :index, as: :json++ expect(row_for(unrelated_order)['order_group_id']).to be_nil+ end+ end++ # The dashboard's filters send prefixed ids, which is what its autocomplete+ # and its links carry — so that is what these assert on.+ describe 'filtering' do+ it 'narrows to one seller' do+ get :index, params: { q: { seller_id_eq: seller.prefixed_id } }, as: :json++ expect(rows.map { |row| row['number'] }).to contain_exactly(seller_order.number)+ end++ it 'narrows to several sellers at once, as the picker sends them' do+ get :index, params: { q: { seller_id_in: [seller.prefixed_id, other_seller.prefixed_id] } }, as: :json++ expect(rows.map { |row| row['number'] }).to contain_exactly(seller_order.number, unrelated_order.number)+ end++ it 'narrows to the orders of one purchase' do+ get :index, params: { q: { order_group_id_eq: group.prefixed_id } }, as: :json++ expect(rows.map { |row| row['number'] }).to contain_exactly(seller_order.number, first_party_order.number)+ end+ end+enddiff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rbindex a159f60b46..a682836f75 100644--- a/spree/core/app/models/spree/order.rb+++ b/spree/core/app/models/spree/order.rb@@ -107,10 +107,10 @@ module Spree# Rails auto-locking must not raise on internal saves.self.lock_optimistically = false- self.whitelisted_ransackable_associations = %w[fulfillments shipments customer created_by approver canceler promotions bill_address ship_address line_items store channel tags]+ self.whitelisted_ransackable_associations = %w[fulfillments shipments customer created_by approver canceler promotions bill_address ship_address line_items store channel tags seller order_group]self.whitelisted_ransackable_attributes = %w[completed_at email number status payment_status payment_state fulfillment_status shipment_state delivery_total- total item_total total_quantity considered_risky channel_id currency coupon_code+ total item_total total_quantity considered_risky channel_id currency coupon_code seller_id order_group_id]self.whitelisted_ransackable_scopes = %w[complete incomplete refunded partially_refunded search multi_search]