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.

Tell seller stock locations apart in the operator's list

Damian Legawiece5700489542b
diff --git a/packages/admin-sdk/src/types/generated/StockLocation.ts b/packages/admin-sdk/src/types/generated/StockLocation.ts
index c1922c5371..471f45d193 100644
--- a/packages/admin-sdk/src/types/generated/StockLocation.ts
+++ b/packages/admin-sdk/src/types/generated/StockLocation.ts
@@ -1,6 +1,7 @@
-// Typelizer digest 11972f44e75f3a95c88825fe54e2c038
+// Typelizer digest 0b79562763bfa3707ff77b0c2c998dc5
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Seller} from '@/types'
interface StockLocation {
id: string;
@@ -14,7 +15,6 @@ interface StockLocation {
state_text: string | null;
pickup_ready_in_minutes: number | null;
pickup_instructions: string | null;
- external_references: Record<string, string>;
admin_name: string | null;
address2: string | null;
state_name: string | null;
@@ -29,6 +29,9 @@ interface StockLocation {
pickup_stock_policy: string;
created_at: string;
updated_at: string;
+ seller_id: string | null;
+ seller_name: string | null;
+ seller?: Seller;
}
export default StockLocation;
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.json
index 4b24f248a7..9683694aa9 100644
--- a/packages/dashboard-core/src/locales/ar.json
+++ b/packages/dashboard-core/src/locales/ar.json
@@ -773,6 +773,7 @@
"default": "تقصير",
"location": "موقع",
"pickup": "يلتقط",
+ "seller": "البائع",
"type": "يكتب"
},
"create_description": "أضف مستودعًا أو متجرًا أو نقطة استلام لتلبية الطلبات منها.",
@@ -783,6 +784,7 @@
},
"edit_description": "تحديث الاسم أو العنوان أو الالتقاط أو سياسات المخزون.",
"empty": "لا توجد مواقع المخزون حتى الآن",
+ "first_party": "السوق",
"kinds": {
"fulfillment_center": "Fulfillment center",
"store": "محل",
diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.json
index bb83a84a37..ffdbdceec1 100644
--- a/packages/dashboard-core/src/locales/de.json
+++ b/packages/dashboard-core/src/locales/de.json
@@ -773,6 +773,7 @@
"default": "Standard",
"location": "Standort",
"pickup": "Abholung",
+ "seller": "Verkäufer",
"type": "Typ"
},
"create_description": "Fügen Sie ein Lager, ein Geschäft oder einen Abholpunkt hinzu, von dem aus Bestellungen abgewickelt werden.",
@@ -783,6 +784,7 @@
},
"edit_description": "Aktualisieren Sie Name, Adresse, Abholung oder Bestandsrichtlinien.",
"empty": "Noch keine Lagerstandorte",
+ "first_party": "Marktplatz",
"kinds": {
"fulfillment_center": "Fulfillment-Center",
"store": "Geschäft",
diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.json
index df62de8f05..733c5b4dd6 100644
--- a/packages/dashboard-core/src/locales/en.json
+++ b/packages/dashboard-core/src/locales/en.json
@@ -775,6 +775,7 @@
"default": "Default",
"location": "Location",
"pickup": "Pickup",
+ "seller": "Seller",
"type": "Type"
},
"create_description": "Add a warehouse, store, or pickup point to fulfill orders from.",
@@ -785,6 +786,7 @@
},
"edit_description": "Update name, address, pickup, or stock policies.",
"empty": "No stock locations yet",
+ "first_party": "Marketplace",
"kinds": {
"fulfillment_center": "Fulfillment center",
"store": "Store",
diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.json
index 61ecd170ee..3fef7a0c89 100644
--- a/packages/dashboard-core/src/locales/fr.json
+++ b/packages/dashboard-core/src/locales/fr.json
@@ -773,6 +773,7 @@
"default": "Par défaut",
"location": "Emplacement",
"pickup": "Retrait",
+ "seller": "Vendeur",
"type": "Type"
},
"create_description": "Ajoutez un entrepôt, un magasin ou un point de retrait pour traiter les commandes.",
@@ -783,6 +784,7 @@
},
"edit_description": "Mettez à jour le nom, l'adresse, le retrait ou les politiques de stock.",
"empty": "Aucun emplacement de stock pour le moment",
+ "first_party": "Place de marché",
"kinds": {
"fulfillment_center": "Centre de distribution",
"store": "Magasin",
diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.json
index 1531aa5f6e..32c91306f9 100644
--- a/packages/dashboard-core/src/locales/pl.json
+++ b/packages/dashboard-core/src/locales/pl.json
@@ -773,6 +773,7 @@
"default": "Domyślna",
"location": "Lokalizacja",
"pickup": "Odbiór",
+ "seller": "Sprzedawca",
"type": "Typ"
},
"create_description": "Dodaj magazyn, sklep lub punkt odbioru, z którego będą realizowane zamówienia.",
@@ -783,6 +784,7 @@
},
"edit_description": "Zaktualizuj nazwę, adres, odbiór lub zasady dotyczące zapasów.",
"empty": "Brak lokalizacji magazynowych",
+ "first_party": "Marketplace",
"kinds": {
"fulfillment_center": "Centrum realizacji zamówień",
"store": "Sklep",
diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.json
index c64e28f6ac..c911b545fb 100644
--- a/packages/dashboard-core/src/locales/zh-CN.json
+++ b/packages/dashboard-core/src/locales/zh-CN.json
@@ -773,6 +773,7 @@
"default": "默认",
"location": "地点",
"pickup": "自提",
+ "seller": "卖家",
"type": "类型"
},
"create_description": "添加仓库、门店或自提点,用于履行订单。",
@@ -783,6 +784,7 @@
},
"edit_description": "更新名称、地址、自提或库存策略。",
"empty": "暂无库存地点",
+ "first_party": "平台自营",
"kinds": {
"fulfillment_center": "履约中心",
"store": "门店",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations.tsx
index 7c35e18c83..6eaf0156b6 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations.tsx
@@ -2,6 +2,8 @@ import { StockLocationsPage, stockLocationsSearchSchema } from '@spree/dashboard
import { createFileRoute } from '@tanstack/react-router'
import type { z } from 'zod/v4'
import { StockLevelsPanel } from '../../../../components/spree/stock-levels-panel'
+// Adds the seller column to the shared table — operator-only, see the file.
+import '../../../../tables/stock-locations'
export const Route = createFileRoute('/_authenticated/$storeId/settings/stock-locations')({
validateSearch: stockLocationsSearchSchema,
diff --git a/packages/dashboard/src/tables/stock-locations.tsx b/packages/dashboard/src/tables/stock-locations.tsx
new file mode 100644
index 0000000000..ff6d5ce473
--- /dev/null
+++ b/packages/dashboard/src/tables/stock-locations.tsx
@@ -0,0 +1,38 @@
+import type { StockLocation } from '@spree/admin-sdk'
+import { tables } from '@spree/dashboard-core'
+import { Badge } from '@spree/dashboard-ui'
+import i18n from 'i18next'
+import { sellerAutocompleteProps } from '../hooks/use-sellers'
+
+/**
+ * Adds one column to the shared stock-locations table: whose location a row
+ * is.
+ *
+ * It belongs to the operator alone. On a marketplace their list holds their
+ * own locations and every seller's together, and without this the two are
+ * indistinguishable — while in a seller's panel every row is theirs already,
+ * so the column would repeat the page's own subject on every line.
+ *
+ * A column added to the shared definition rather than a second table: the
+ * registry exists for exactly this, and a fork would have to be kept in step
+ * with the original by hand.
+ */
+tables['stock-locations'].addColumn<StockLocation>({
+ key: 'seller_id',
+ label: i18n.t('admin.stock_locations.columns.seller'),
+ default: true,
+ filterable: true,
+ filterType: 'resource',
+ // `seller_id_in` — whitelisted on StockLocation alongside the `seller`
+ // association, so the filter narrows to one or more sellers.
+ ransackAttribute: 'seller_id',
+ filterResource: sellerAutocompleteProps('stock-location-seller-picker'),
+ render: (location) =>
+ location.seller_name ? (
+ <Badge variant="outline">{location.seller_name}</Badge>
+ ) : (
+ // Not a dash: "no seller" is a positive fact here — the location is the
+ // marketplace's own — and a dash would read as missing data.
+ <span className="text-muted-foreground">{i18n.t('admin.stock_locations.first_party')}</span>
+ ),
+})
diff --git a/spree/api/app/serializers/spree/api/v3/admin/stock_location_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/stock_location_serializer.rb
index 9e5a943ffc..d0aae4042e 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/stock_location_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/stock_location_serializer.rb
@@ -5,7 +5,8 @@ module Spree
class StockLocationSerializer < V3::StockLocationSerializer
include Concerns::ExternalReferencesAttribute
- typelize active: :boolean, default: :boolean, backorderable_default: :boolean,
+ typelize seller_id: [:string, nullable: true], seller_name: [:string, nullable: true],
+ active: :boolean, default: :boolean, backorderable_default: :boolean,
propagate_all_variants: :boolean, pickup_enabled: :boolean,
admin_name: [:string, nullable: true],
address2: [:string, nullable: true], state_name: [:string, nullable: true],
@@ -19,6 +20,22 @@ module Spree
:kind, :pickup_enabled, :pickup_stock_policy,
:pickup_ready_in_minutes, :pickup_instructions,
created_at: :iso8601, updated_at: :iso8601
+
+ # Whose shelf this is — nil for the marketplace's own. On a
+ # marketplace the operator's list holds both, and without this the
+ # two are indistinguishable. The name rides along so the list can
+ # show it without expanding; the full profile is `?expand=seller`.
+ attribute :seller_id do |stock_location|
+ stock_location.seller&.prefixed_id
+ end
+
+ attribute :seller_name do |stock_location|
+ stock_location.seller&.name
+ end
+
+ one :seller,
+ resource: proc { Spree.api.admin_seller_serializer },
+ if: proc { expand?('seller') }
end
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/stock_locations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/stock_locations_controller_spec.rb
index 0535b5d448..4703c3e290 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/stock_locations_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/stock_locations_controller_spec.rb
@@ -22,6 +22,34 @@ RSpec.describe Spree::Api::V3::Admin::StockLocationsController, type: :controlle
expect(ids).to include(stock_location.prefixed_id, other_location.prefixed_id)
end
+ # On a marketplace this list holds the operator's own locations and every
+ # seller's together, so each row has to say which it is.
+ context 'with seller-owned locations' do
+ let(:seller) { create(:seller, store: store, name: 'Bright Sparks') }
+ let!(:seller_location) do
+ seller.stock_locations.create!(store: store, name: 'Seller Depot')
+ end
+
+ it 'names the seller on their rows and leaves the operator rows blank' do
+ get :index, as: :json
+
+ rows = json_response['data'].index_by { |sl| sl['id'] }
+ expect(rows[seller_location.prefixed_id]).to include(
+ 'seller_id' => seller.prefixed_id, 'seller_name' => 'Bright Sparks'
+ )
+ expect(rows[stock_location.prefixed_id]).to include(
+ 'seller_id' => nil, 'seller_name' => nil
+ )
+ end
+
+ it 'filters to one seller' do
+ get :index, params: { q: { seller_id_in: [seller.id] } }, as: :json
+
+ ids = json_response['data'].map { |sl| sl['id'] }
+ expect(ids).to eq([seller_location.prefixed_id])
+ end
+ end
+
it 'includes the new pickup attributes' do
get :index, as: :json
diff --git a/spree/core/app/models/spree/stock_location.rb b/spree/core/app/models/spree/stock_location.rb
index 7586ca8bce..7706179b45 100644
--- a/spree/core/app/models/spree/stock_location.rb
+++ b/spree/core/app/models/spree/stock_location.rb
@@ -48,7 +48,9 @@ module Spree
self.whitelisted_ransackable_attributes = %w[
name active default kind pickup_enabled
country_code state_code created_at updated_at
+ seller_id
]
+ self.whitelisted_ransackable_associations = %w[seller]
scope :active, -> { where(active: true) }
scope :pickup_enabled, -> { where(pickup_enabled: true) }