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 channels in both admins on order / products and ability to filter by channels there
Damian Legawiec4b18b36001b1
diff --git a/packages/dashboard-ui/src/spree/form-actions.tsx b/packages/dashboard-ui/src/spree/form-actions.tsxindex 54d6b776e4..b53f4c2745 100644--- a/packages/dashboard-ui/src/spree/form-actions.tsx+++ b/packages/dashboard-ui/src/spree/form-actions.tsx@@ -7,8 +7,7 @@ import { Button } from '../ui/button'/*** Submit button wired to a `react-hook-form` instance. Always rendered,* disabled until the form is dirty. Replaces the legacy "footer pops up- * when something changes" pattern with the always-visible header pattern- * Linear and modern Shopify use.+ * when something changes" pattern with an always-visible header.** Reads `isDirty` and `isSubmitting` from the RHF form state via* `useFormState`, so the button re-renders independently of the parent pagediff --git a/packages/dashboard/src/components/spree/custom-fields/definition-form.tsx b/packages/dashboard/src/components/spree/custom-fields/definition-form.tsxindex 529a91711f..05b72dd470 100644--- a/packages/dashboard/src/components/spree/custom-fields/definition-form.tsx+++ b/packages/dashboard/src/components/spree/custom-fields/definition-form.tsx@@ -226,7 +226,7 @@ export function DefinitionFormFields({interface DefinitionFormProps {resourceType: string- /** Default namespace; "custom" mirrors Shopify/Saleor convention. */+ /** Default namespace. */defaultNamespace?: stringonSuccess: (definitionId: string) => void/**diff --git a/packages/dashboard/src/components/spree/products/publishing-card.tsx b/packages/dashboard/src/components/spree/products/publishing-card.tsxindex 398e27a6aa..12f490696d 100644--- a/packages/dashboard/src/components/spree/products/publishing-card.tsx+++ b/packages/dashboard/src/components/spree/products/publishing-card.tsx@@ -28,9 +28,8 @@ import type { ProductFormValues } from '@/schemas/product'type ProductForm = UseFormReturn<ProductFormValues>// `not_available` short-circuits when the product status (Draft/Archived) blocks-// customer visibility, even if the per-channel publication window is open. Matches-// Shopify's behavior: the product status is the outer gate; per-channel scheduling-// only matters once status is Active.+// customer visibility, even if the per-channel publication window is open. Product+// status is the outer gate; per-channel scheduling only matters once status is Active.type ScheduleStatus = 'live' | 'scheduled' | 'hidden' | 'not_available'function scheduleStatus(diff --git a/packages/dashboard/src/hooks/use-order.ts b/packages/dashboard/src/hooks/use-order.tsindex b1711f49cd..a75ce5706e 100644--- a/packages/dashboard/src/hooks/use-order.ts+++ b/packages/dashboard/src/hooks/use-order.ts@@ -23,6 +23,7 @@ export function useOrder(orderId: string) {'canceler','approver','market',+ 'channel',],}),enabled: !!orderId,diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsxindex ac9f807d7b..1f61603811 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/$orderId.tsx@@ -1339,6 +1339,13 @@ function OrderSummaryCard({ order }: { order: Order }) {<Separator />+ {order.channel && (+ <SummaryRow+ label={t('admin.pages.orders.detail.summary.channel')}+ value={order.channel.name}+ />+ )}+{order.market && (<SummaryRowlabel={t('admin.pages.orders.detail.summary.market')}diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/drafts.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/drafts.tsxindex 3db41fbeb4..ffa7c5295f 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/drafts.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/drafts.tsx@@ -20,7 +20,7 @@ function DraftOrdersPage() {queryKey="draft-orders"queryFn={(params) => adminClient.orders.list(params)}searchParams={searchParams}- defaultParams={{ incomplete: 1 }}+ defaultParams={{ incomplete: 1, expand: ['channel'] }}title={t('admin.pages.orders.drafts_title')}actions={<Button size="sm" className="h-[2.125rem]">diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/orders/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/orders/index.tsxindex 33cf55a32b..b3ea521db0 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/orders/index.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/orders/index.tsx@@ -24,7 +24,7 @@ function OrdersPage() {queryKey="orders"queryFn={(params) => adminClient.orders.list(params)}searchParams={searchParams}- defaultParams={{ complete: 1 }}+ defaultParams={{ complete: 1, expand: ['channel'] }}actions={(ctx) => (<><ExportButton type="Spree::Exports::Orders" {...ctx} />diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsxindex 3ddbb5ff54..ec0705fe5d 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx@@ -37,8 +37,7 @@ function NewProductPage() {const { data: channelsResponse } = useChannels()// Pre-select the store's default channel so a freshly-created product is// visible on the storefront without the merchant having to open the- // Publishing card. Mirrors Shopify's autoPublish behavior on the Online- // Store channel — the merchant can untick channels post-create.+ // Publishing card. Merchant can untick channels post-create.const defaultChannelId = channelsResponse?.data.find((c) => c.default)?.idconst form = useForm<CreateValues>({diff --git a/packages/dashboard/src/tables/orders.tsx b/packages/dashboard/src/tables/orders.tsxindex 4c87c88d09..5331b42e41 100644--- a/packages/dashboard/src/tables/orders.tsx+++ b/packages/dashboard/src/tables/orders.tsx@@ -47,6 +47,18 @@ defineTable('orders', {className: 'text-sm',render: (order) => order.email ?? '—',},+ {+ key: 'channel',+ label: i18n.t('admin.fields.order.channel.label'),+ sortable: true,+ filterable: true,+ filterType: 'resource',+ filterResource: channelAutocompleteProps('orders-table-channel-filter'),+ ransackAttribute: 'channel_id',+ default: true,+ className: 'text-sm text-muted-foreground',+ render: (order) => order.channel?.name ?? '—',+ },{key: 'payment_status',label: 'Payment',@@ -176,15 +188,5 @@ defineTable('orders', {displayable: false,ransackAttribute: 'line_items_variant_sku',},- {- key: 'channels',- label: i18n.t('admin.fields.product.channels.label'),- filterable: true,- filterType: 'resource',- filterResource: channelAutocompleteProps('orders-table-channel-filter'),- ransackAttribute: 'channel_id',- displayable: false,- default: false,- },],})diff --git a/spree/admin/app/presenters/spree/admin/order_summary_presenter.rb b/spree/admin/app/presenters/spree/admin/order_summary_presenter.rbindex 0287d67c17..218f79fed7 100644--- a/spree/admin/app/presenters/spree/admin/order_summary_presenter.rb+++ b/spree/admin/app/presenters/spree/admin/order_summary_presenter.rb@@ -13,6 +13,7 @@ module Spree[*metadata_rows,:separator,+ channel_row,market_row,locale_row,currency_row,@@ -73,6 +74,17 @@ module Spreerowsend+ def channel_row+ return nil if order.channel.blank?++ {+ label: Spree.t(:channel),+ value: order.channel.name,+ id: 'channel',+ link: Spree::Core::Engine.routes.url_helpers.edit_admin_channel_path(order.channel)+ }+ end+def market_rowreturn nil if order.market.blank?diff --git a/spree/admin/config/initializers/spree_admin_tables.rb b/spree/admin/config/initializers/spree_admin_tables.rbindex 9874e9d41d..19e70b4d5e 100644--- a/spree/admin/config/initializers/spree_admin_tables.rb+++ b/spree/admin/config/initializers/spree_admin_tables.rb@@ -128,6 +128,19 @@ Rails.application.config.after_initialize dosearch_url: ->(view_context) { view_context.spree.admin_tags_select_options_path(format: :json, taggable_type: 'Spree::Product') },method: ->(product) { product.tag_list.to_sentence }+ Spree.admin.tables.products.add :channels,+ label: :channels,+ type: :association,+ filter_type: :select,+ sortable: false,+ filterable: true,+ default: false,+ position: 90,+ ransack_attribute: 'channels_id',+ operators: %i[in not_in],+ value_options: -> { Spree::Current.store&.channels&.order(:name)&.pluck(:name, :id)&.map { |name, id| { value: id, label: name } } || [] },+ method: ->(product) { product.channels.pluck(:name).to_sentence }+# Products bulk actionsSpree.admin.tables.products.add_bulk_action :set_active,label: 'admin.bulk_ops.products.title.set_active',@@ -350,6 +363,19 @@ Rails.application.config.after_initialize dooperators: %i[in],search_url: ->(view_context) { view_context.spree.select_options_admin_promotions_path(format: :json) }+ Spree.admin.tables.orders.add :channel,+ label: :channel,+ type: :association,+ filter_type: :select,+ sortable: true,+ filterable: true,+ default: true,+ position: 35,+ ransack_attribute: 'channel_id',+ operators: %i[eq not_eq in not_in],+ value_options: -> { Spree::Current.store&.channels&.order(:name)&.pluck(:name, :id)&.map { |name, id| { value: id, label: name } } || [] },+ method: ->(order) { order.channel&.name }+# Register Checkouts table (draft orders)Spree.admin.tables.register(:checkouts, model_class: Spree::Order, search_param: :search, date_range_param: :created_at, new_resource: false)diff --git a/spree/admin/spec/presenters/spree/admin/order_summary_presenter_spec.rb b/spree/admin/spec/presenters/spree/admin/order_summary_presenter_spec.rbindex fd2fce9785..7830554076 100644--- a/spree/admin/spec/presenters/spree/admin/order_summary_presenter_spec.rb+++ b/spree/admin/spec/presenters/spree/admin/order_summary_presenter_spec.rb@@ -79,6 +79,30 @@ RSpec.describe Spree::Admin::OrderSummaryPresenter doendend+ describe '#channel_row' do+ subject { presenter.channel_row }++ context 'when order has a channel' do+ let(:channel) { create(:channel, store: order.store, name: 'Point of Sale', code: 'pos') }+ before { order.update!(channel: channel) }++ it 'returns channel info with an edit link' do+ expect(subject[:label]).to eq(Spree.t(:channel))+ expect(subject[:value]).to eq('Point of Sale')+ expect(subject[:id]).to eq('channel')+ expect(subject[:link]).to eq(Spree::Core::Engine.routes.url_helpers.edit_admin_channel_path(channel))+ end+ end++ context 'when order has no channel' do+ before { order.update_column(:channel_id, nil) }++ it 'returns nil' do+ expect(subject).to be_nil+ end+ end+ end+describe '#locale_row' dosubject { presenter.locale_row }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 3dccf36e07..4308b227b6 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@@ -124,7 +124,7 @@ module Spreeenddef collection_includes- [:line_items, :user, :rich_text_internal_note]+ [:line_items, :user, :channel, :rich_text_internal_note]endprivatediff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rbindex 1ffc612c63..93e59a664a 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb@@ -44,6 +44,29 @@ RSpec.describe Spree::Api::V3::Admin::OrdersController, type: :controller doexpect(json_response['data'].length).to eq(1)expect(json_response['data'].first['id']).to eq(completed_order.prefixed_id)end++ context 'filtering by channel_id' do+ let(:pos_channel) { create(:channel, store: store, code: 'pos', name: 'POS') }+ let!(:pos_order) { create(:order, store: store, channel: pos_channel) }+ let!(:default_channel_order) { create(:order, store: store, channel: store.default_channel) }++ it 'returns only orders on the requested channel via channel_id_eq' do+ get :index, params: { q: { channel_id_eq: pos_channel.id } }, as: :json++ expect(response).to have_http_status(:ok)+ ids = json_response['data'].map { |o| o['id'] }+ expect(ids).to include(pos_order.prefixed_id)+ expect(ids).not_to include(default_channel_order.prefixed_id)+ end++ it 'returns orders across multiple channels via channel_id_in' do+ get :index, params: { q: { channel_id_in: [pos_channel.id, store.default_channel.id] } }, as: :json++ expect(response).to have_http_status(:ok)+ ids = json_response['data'].map { |o| o['id'] }+ expect(ids).to include(pos_order.prefixed_id, default_channel_order.prefixed_id)+ end+ endendcontext 'with q[search] (full-text search)' dodiff --git a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rbindex 2162265edb..defbe17481 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/products_controller_spec.rb@@ -45,6 +45,30 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller doexpect(json_response['data'].length).to eq(1)expect(json_response['data'].first['id']).to eq(other_product.prefixed_id)end++ context 'filtering by channel via channels_id_in' do+ let(:pos_channel) { create(:channel, store: store, code: 'pos', name: 'POS') }+ let!(:pos_product) { create(:product, store: store) }+ let!(:default_channel_product) { create(:product, store: store) }++ before do+ # Override the auto-publish on the default channel so each product is+ # on exactly one channel — clean assertion target.+ pos_product.product_publications.destroy_all+ default_channel_product.product_publications.destroy_all+ pos_channel.add_products([pos_product.id])+ store.default_channel.add_products([default_channel_product.id])+ end++ it 'returns only products published on the requested channel' do+ get :index, params: { q: { channels_id_in: [pos_channel.id] } }, as: :json++ expect(response).to have_http_status(:ok)+ ids = json_response['data'].map { |p| p['id'] }+ expect(ids).to include(pos_product.prefixed_id)+ expect(ids).not_to include(default_channel_product.prefixed_id)+ end+ endend# Regression for SPA pickers (`<ResourceMultiAutocomplete>` hydration):