Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Let merchants pick a channel's default catalog (#14513)

Damian Legawiec01fecd5a4865
diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.ts
index e90578c508..80159bacdc 100644
--- a/packages/admin-sdk/src/params.ts
+++ b/packages/admin-sdk/src/params.ts
@@ -1499,6 +1499,11 @@ export interface ChannelCreateParams {
* store-level preference.
*/
preferred_guest_checkout?: boolean | null
+ /**
+ * Catalog (cat_...) shown to shoppers not covered by a company or customer
+ * group catalog. `null` means every product published on the channel.
+ */
+ default_catalog_id?: string | null
/** Fulfillment-origin allowlist (sloc_...); replaces the full set. Empty means every store location serves this channel. */
stock_location_ids?: string[]
}
@@ -1519,6 +1524,11 @@ export interface ChannelUpdateParams {
* store-level preference.
*/
preferred_guest_checkout?: boolean | null
+ /**
+ * Catalog (cat_...) shown to shoppers not covered by a company or customer
+ * group catalog. `null` means every product published on the channel.
+ */
+ default_catalog_id?: string | null
/** Fulfillment-origin allowlist (sloc_...); replaces the full set. Empty means every store location serves this channel. */
stock_location_ids?: string[]
}
diff --git a/packages/dashboard-core/src/components/resource-combobox.tsx b/packages/dashboard-core/src/components/resource-combobox.tsx
index 84c414e4c9..7007036495 100644
--- a/packages/dashboard-core/src/components/resource-combobox.tsx
+++ b/packages/dashboard-core/src/components/resource-combobox.tsx
@@ -20,6 +20,7 @@ export interface ResourceComboboxProps<T extends ComboboxOption>
| 'placeholder'
| 'emptyText'
| 'disabled'
+ | 'id'
> {
/**
* Server-side search. Called as the user types (debounced via React's
@@ -69,6 +70,7 @@ export function ResourceCombobox<T extends ComboboxOption>({
emptyText,
disabled,
filterOption,
+ id,
}: ResourceComboboxProps<T>) {
const { t } = useTranslation()
const placeholderLabel = placeholder ?? t('admin.common.search_placeholder')
@@ -126,6 +128,7 @@ export function ResourceCombobox<T extends ComboboxOption>({
placeholder={placeholderLabel}
emptyText={emptyLabel}
disabled={disabled}
+ id={id}
/>
)
}
diff --git a/packages/dashboard-ui/src/spree/resource-combobox.tsx b/packages/dashboard-ui/src/spree/resource-combobox.tsx
index a39a0db535..4fe0c1631d 100644
--- a/packages/dashboard-ui/src/spree/resource-combobox.tsx
+++ b/packages/dashboard-ui/src/spree/resource-combobox.tsx
@@ -50,6 +50,12 @@ export interface ResourceComboboxProps<T extends ComboboxOption> {
/** Empty state text shown in the dropdown when items is empty. */
emptyText?: string
disabled?: boolean
+
+ /**
+ * Applied to the search input, so a sibling `<FieldLabel htmlFor>` names the
+ * field for screen readers.
+ */
+ id?: string
}
/**
@@ -73,6 +79,7 @@ export function ResourceCombobox<T extends ComboboxOption>({
placeholder,
emptyText,
disabled,
+ id,
}: ResourceComboboxProps<T>) {
const selected = items.find((r) => r.id === value) ?? null
@@ -92,7 +99,7 @@ export function ResourceCombobox<T extends ComboboxOption>({
// dropdown trigger + selection mechanics, not just the input.
disabled={disabled}
>
- <ComboboxInput placeholder={placeholder} disabled={disabled} showClear />
+ <ComboboxInput id={id} placeholder={placeholder} disabled={disabled} showClear />
<ComboboxContent>
<ComboboxEmpty>{emptyText}</ComboboxEmpty>
<ComboboxList>
diff --git a/packages/dashboard/e2e/channels-settings.spec.ts b/packages/dashboard/e2e/channels-settings.spec.ts
index aaf842b869..77dde84d15 100644
--- a/packages/dashboard/e2e/channels-settings.spec.ts
+++ b/packages/dashboard/e2e/channels-settings.spec.ts
@@ -90,6 +90,21 @@ test.describe('settings / channels', () => {
await expect(rowButton(page, updated)).toBeVisible({ timeout: 15_000 })
})
+ test('names the default catalog picker for assistive technology', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CHANNELS_PATH(creds.store_id), ADD_CTA)
+
+ await page.getByRole('button', { name: ADD_CTA }).click()
+ await expect(page.getByRole('heading', { name: /add sales channel/i })).toBeVisible()
+
+ // Resolving the combobox by its visible label is the whole point: the
+ // picker is a custom widget, so without the label wired to the input a
+ // screen reader announces an unnamed field.
+ const picker = page.getByLabel(/^default catalog$/i)
+ await expect(picker).toBeVisible()
+ await expect(picker).toHaveAttribute('placeholder', /all published products/i)
+ })
+
test('manages order routing rules on a channel', async ({ page }) => {
const creds = await login(page)
await gotoIndex(page, CHANNELS_PATH(creds.store_id), ADD_CTA)
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 95464d8821..d7c9911bef 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -910,6 +910,12 @@
"help": "قناة واحدة فقط لكل متجر هي الافتراضية. تُستخدم كبديل عند عدم اختيار قناة وكهدف نشر تلقائي للمنتجات الجديدة.",
"label": "القناة الافتراضية"
},
+ "default_catalog": {
+ "empty": "لم يتم العثور على كتالوجات",
+ "help": "ما يراه المتسوقون غير المشمولين بأي كتالوج شركة أو مجموعة عملاء. اتركه فارغًا لعرض جميع المنتجات المنشورة على هذه القناة.",
+ "label": "الكتالوج الافتراضي",
+ "placeholder": "جميع المنتجات المنشورة"
+ },
"fulfillment_locations": {
"all": "جميع المواقع",
"help": "المستودعات ونقاط الاستلام التي تنفّذ الطلبات الواردة من قناة البيع هذه.",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 0e8a64b200..5651771c12 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -893,6 +893,12 @@
"help": "Pro Store ist genau ein Kanal der Standard. Wird als Fallback verwendet, wenn kein Kanal ausgewählt ist, und als Auto-Veröffentlichungsziel für neue Produkte.",
"label": "Standardkanal"
},
+ "default_catalog": {
+ "empty": "Keine Kataloge gefunden",
+ "help": "Was Käufer sehen, die keinem Unternehmens- oder Kundengruppenkatalog zugeordnet sind. Leer lassen, um alle auf diesem Kanal veröffentlichten Produkte anzuzeigen.",
+ "label": "Standardkatalog",
+ "placeholder": "Alle veröffentlichten Produkte"
+ },
"fulfillment_locations": {
"all": "Alle Standorte",
"help": "Welche Lager und Abholstationen Bestellungen aus diesem Verkaufskanal erfüllen.",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 2606575ece..697414a0cd 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -893,6 +893,12 @@
"help": "Exactly one channel per store is the default. Used as the fallback when no channel is selected and as the auto-publish target for new products.",
"label": "Default channel"
},
+ "default_catalog": {
+ "empty": "No catalogs found",
+ "help": "What shoppers outside any company or customer group catalog see. Leave blank to show every product published on this channel.",
+ "label": "Default catalog",
+ "placeholder": "All published products"
+ },
"fulfillment_locations": {
"all": "All locations",
"help": "Which warehouses and pickup counters fulfill orders placed on this sales channel.",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 4bdb5492b5..d6a972e190 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -893,6 +893,12 @@
"help": "Exactement un canal par boutique est défini par défaut. Utilisé comme solution de repli lorsqu'aucun canal n'est sélectionné et comme cible de publication automatique pour les nouveaux produits.",
"label": "Canal par défaut"
},
+ "default_catalog": {
+ "empty": "Aucun catalogue trouvé",
+ "help": "Ce que voient les acheteurs auxquels aucun catalogue d’entreprise ou de groupe de clients ne s’applique. Laissez vide pour afficher tous les produits publiés sur ce canal.",
+ "label": "Catalogue par défaut",
+ "placeholder": "Tous les produits publiés"
+ },
"fulfillment_locations": {
"all": "Tous les sites",
"help": "Quels entrepôts et points de retrait traitent les commandes passées sur ce canal de vente.",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 38e7f11463..7f86e3c5ef 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -911,6 +911,12 @@
"help": "Dokładnie jeden kanał na sklep jest domyślny. Używany jako rozwiązanie zastępcze, gdy nie wybrano żadnego kanału, oraz jako cel automatycznej publikacji nowych produktów.",
"label": "Kanał domyślny"
},
+ "default_catalog": {
+ "empty": "Nie znaleziono katalogów",
+ "help": "To, co widzą kupujący nieobjęci żadnym katalogiem firmy ani grupy klientów. Pozostaw puste, aby pokazać wszystkie produkty opublikowane w tym kanale.",
+ "label": "Katalog domyślny",
+ "placeholder": "Wszystkie opublikowane produkty"
+ },
"fulfillment_locations": {
"all": "Wszystkie lokalizacje",
"help": "Które magazyny i punkty odbioru realizują zamówienia z tego kanału sprzedaży.",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 1ad03a2556..b65d83d21c 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -888,6 +888,12 @@
"help": "每个商店有且仅有一个默认渠道。在未选择渠道时用作回退,并作为新产品的自动发布目标。",
"label": "默认渠道"
},
+ "default_catalog": {
+ "empty": "未找到目录",
+ "help": "不属于任何公司或客户组目录的买家所看到的内容。留空则显示此渠道上发布的所有商品。",
+ "label": "默认目录",
+ "placeholder": "所有已发布商品"
+ },
"fulfillment_locations": {
"all": "所有地点",
"help": "哪些仓库和自提点负责履行此销售渠道的订单。",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/channels.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/channels.tsx
index 1d1a253369..ab41b68774 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/channels.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/channels.tsx
@@ -1,9 +1,10 @@
import { zodResolver } from '@hookform/resolvers/zod'
-import type { Channel, ChannelCreateParams } from '@spree/admin-sdk'
+import type { Catalog, Channel, ChannelCreateParams } from '@spree/admin-sdk'
import {
adminClient,
Can,
mapSpreeErrorsToForm,
+ ResourceCombobox,
ResourceTable,
resourceSearchSchema,
Subject,
@@ -256,6 +257,7 @@ function EditChannelSheet({
preferred_storefront_access: channel.preferred_storefront_access ?? '',
preferred_guest_checkout:
channel.preferred_guest_checkout == null ? '' : String(channel.preferred_guest_checkout),
+ default_catalog_id: channel.default_catalog_id ?? '',
stock_location_ids: channel.stock_location_ids ?? [],
})
}
@@ -468,11 +470,52 @@ function ChannelFormFields({ form }: { form: UseFormReturn<ChannelFormValues> })
values={GUEST_CHECKOUT_VALUES}
/>
+ <DefaultCatalogField form={form} />
+
<FulfillmentLocationsField form={form} />
</FieldGroup>
)
}
+/**
+ * What shoppers outside any company or customer-group catalog see on this
+ * channel — the last branch of the visibility precedence, so a company buyer
+ * sees their own catalogs instead of this one. A curated catalog here makes
+ * the rest of the channel's range private; one with an empty assortment
+ * prices only and hides nothing.
+ */
+function DefaultCatalogField({ form }: { form: UseFormReturn<ChannelFormValues> }) {
+ const { t } = useTranslation()
+
+ return (
+ <Field>
+ <FieldLabel htmlFor="channel-default-catalog">
+ {t('admin.fields.channel.default_catalog.label')}
+ </FieldLabel>
+ <Controller
+ name="default_catalog_id"
+ control={form.control}
+ render={({ field }) => (
+ <ResourceCombobox<Catalog>
+ id="channel-default-catalog"
+ queryKey="channel-default-catalogs"
+ search={(q) => adminClient.catalogs.list({ name_cont: q, limit: 10 })}
+ hydrate={(ids) => adminClient.catalogs.list({ id_in: ids, limit: ids.length })}
+ getOptionLabel={(catalog) => catalog.name}
+ placeholder={t('admin.fields.channel.default_catalog.placeholder')}
+ emptyText={t('admin.fields.channel.default_catalog.empty')}
+ value={field.value || undefined}
+ onChange={(id) => field.onChange(id ?? '')}
+ />
+ )}
+ />
+ <span className="text-xs text-muted-foreground">
+ {t('admin.fields.channel.default_catalog.help')}
+ </span>
+ </Field>
+ )
+}
+
/**
* Which warehouses and counters fulfill this channel's orders. Narrowing is
* the exception — a channel serves every location of the store until the
diff --git a/packages/dashboard/src/schemas/channel.ts b/packages/dashboard/src/schemas/channel.ts
index 77c0449bfa..c0efc8a4d5 100644
--- a/packages/dashboard/src/schemas/channel.ts
+++ b/packages/dashboard/src/schemas/channel.ts
@@ -34,6 +34,9 @@ export const channelFormSchema = z.object({
preferred_order_routing_strategy: z.string(),
preferred_storefront_access: z.string(),
preferred_guest_checkout: z.string(),
+ // Empty means shoppers outside any assigned catalog see every product
+ // published on the channel.
+ default_catalog_id: z.string(),
// Empty means every location of the store serves this channel, which is how
// the API reads an empty array.
stock_location_ids: z.array(z.string()),
@@ -49,9 +52,15 @@ export const CHANNEL_DEFAULTS: ChannelFormValues = {
preferred_order_routing_strategy: '',
preferred_storefront_access: '',
preferred_guest_checkout: '',
+ default_catalog_id: '',
stock_location_ids: [],
}
+/**
+ * Maps form values to the Admin API payload. Every blank override is sent as
+ * null rather than omitted: clearing a field on an existing channel has to
+ * restore the inherited behavior, which an omitted key would not do.
+ */
export function channelValuesToParams(
v: ChannelFormValues,
): ChannelCreateParams & ChannelUpdateParams {
@@ -65,6 +74,9 @@ export function channelValuesToParams(
// '' → inherit (null); otherwise an explicit boolean.
preferred_guest_checkout:
v.preferred_guest_checkout === '' ? null : v.preferred_guest_checkout === 'true',
+ // '' → no default catalog: shoppers outside any assigned catalog see
+ // every product published on the channel.
+ default_catalog_id: v.default_catalog_id || null,
// Replace-set: an empty array clears the narrowing, so every location
// serves the channel again.
stock_location_ids: v.stock_location_ids,
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/channels_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/channels_controller_spec.rb
index 3b5572e528..7bcdbdba1a 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/channels_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/channels_controller_spec.rb
@@ -330,4 +330,34 @@ RSpec.describe Spree::Api::V3::Admin::ChannelsController, type: :controller do
end
end
+ describe 'default catalog' do
+ let!(:catalog) { create(:catalog, store: store) }
+
+ it 'sets the default catalog and serializes its prefixed id' do
+ patch :update, params: { id: channel.prefixed_id, default_catalog_id: catalog.prefixed_id }, as: :json
+
+ expect(response).to have_http_status(:ok)
+ expect(json_response['default_catalog_id']).to eq(catalog.prefixed_id)
+ expect(channel.reload.default_catalog).to eq(catalog)
+ end
+
+ it 'clears the default catalog when set to null, restoring every published product' do
+ channel.update!(default_catalog: catalog)
+
+ patch :update, params: { id: channel.prefixed_id, default_catalog_id: nil }, as: :json
+
+ expect(response).to have_http_status(:ok)
+ expect(json_response['default_catalog_id']).to be_nil
+ expect(channel.reload.default_catalog).to be_nil
+ end
+
+ it 'rejects a cross-store catalog with 404' do
+ foreign = create(:catalog, store: create(:store))
+
+ patch :update, params: { id: channel.prefixed_id, default_catalog_id: foreign.prefixed_id }, as: :json
+
+ expect(response).to have_http_status(:not_found)
+ expect(channel.reload.default_catalog).to be_nil
+ end
+ end
end