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.

Phase P0.5: Rename stock items to stock levels in the SDK and dashboard

Łukasz Adamczykda49f27a5da1
diff --git a/.changeset/stock-item-renamed-to-stock-level.md b/.changeset/stock-item-renamed-to-stock-level.md
new file mode 100644
index 0000000000..0385e50032
--- /dev/null
+++ b/.changeset/stock-item-renamed-to-stock-level.md
@@ -0,0 +1,15 @@
+---
+'@spree/admin-sdk': major
+'@spree/dashboard': major
+---
+
+Renamed stock items to stock levels.
+
+Spree 6.0 renames `Spree::StockItem` to `Spree::StockLevel`, and the admin API and SDK follow. There is no compatibility shim on the client side, so update your code before upgrading:
+
+- `client.stockItems` is now `client.stockLevels`, and it calls `/stock_levels` instead of `/stock_items`.
+- The `StockItem` type is now `StockLevel`, and `StockItemUpdateParams` is now `StockLevelUpdateParams`.
+- A variant's `stock_items` array is now `stock_levels`, on both reads and writes.
+- Prefixed ids change from `si_…` to `sl_…`. Ids you stored earlier no longer resolve.
+
+Webhook endpoints keep working: Spree publishes both `stock_level.*` and the older `stock_item.*` events for one release, so existing subscriptions keep firing. The dashboard's event picker now offers the `stock_level` names, and shows any `stock_item` subscription you already have under its Custom section. Move your subscriptions over before Spree 6.1, when the old names stop being published.
diff --git a/packages/admin-sdk/examples/products/create.ts b/packages/admin-sdk/examples/products/create.ts
index 7c0ae12f15..5c303267c2 100644
--- a/packages/admin-sdk/examples/products/create.ts
+++ b/packages/admin-sdk/examples/products/create.ts
@@ -23,7 +23,7 @@ const product = await client.products.create({
{ currency: 'USD', amount: '29.99' },
{ currency: 'EUR', amount: '27.99' },
],
- stock_items: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 50 }],
+ stock_levels: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 50 }],
},
{
sku: 'TSHIRT-M-NAVY',
@@ -32,7 +32,7 @@ const product = await client.products.create({
{ name: 'color', value: 'navy' },
],
prices: [{ currency: 'USD', amount: '29.99' }],
- stock_items: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 30 }],
+ stock_levels: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 30 }],
},
],
})
diff --git a/packages/admin-sdk/examples/variants/create.ts b/packages/admin-sdk/examples/variants/create.ts
index 8274b48e50..4bb34fe6b9 100644
--- a/packages/admin-sdk/examples/variants/create.ts
+++ b/packages/admin-sdk/examples/variants/create.ts
@@ -16,7 +16,7 @@ const variant = await client.products.variants.create('prod_86Rf07xd4z', {
{ currency: 'USD', amount: '29.99', compare_at_amount: '34.99' },
{ currency: 'EUR', amount: '27.99' },
],
- stock_items: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 25 }],
+ stock_levels: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 25 }],
})
// endregion:example
diff --git a/packages/admin-sdk/examples/variants/get.ts b/packages/admin-sdk/examples/variants/get.ts
index 26afbc91f4..f70b89d32d 100644
--- a/packages/admin-sdk/examples/variants/get.ts
+++ b/packages/admin-sdk/examples/variants/get.ts
@@ -7,8 +7,9 @@ const client = createAdminClient({
// region:example
const variant = await client.products.variants.get('prod_86Rf07xd4z', 'variant_k5nR8xLq', {
- expand: ['prices', 'stock_items'],
+ expand: ['prices', 'stock_levels'],
})
+
// endregion:example
export { variant }
diff --git a/packages/admin-sdk/examples/variants/list.ts b/packages/admin-sdk/examples/variants/list.ts
index e0bf4a9de0..b48214a420 100644
--- a/packages/admin-sdk/examples/variants/list.ts
+++ b/packages/admin-sdk/examples/variants/list.ts
@@ -7,8 +7,9 @@ const client = createAdminClient({
// region:example
const { data: variants } = await client.products.variants.list('prod_86Rf07xd4z', {
- expand: ['prices', 'stock_items'],
+ expand: ['prices', 'stock_levels'],
})
+
// endregion:example
export { variants }
diff --git a/packages/admin-sdk/examples/variants/update.ts b/packages/admin-sdk/examples/variants/update.ts
index b4f4e81280..3255f0b9b9 100644
--- a/packages/admin-sdk/examples/variants/update.ts
+++ b/packages/admin-sdk/examples/variants/update.ts
@@ -8,10 +8,9 @@ const client = createAdminClient({
// region:example
const variant = await client.products.variants.update('prod_86Rf07xd4z', 'variant_k5nR8xLq', {
sku: 'UPDATED-SKU',
- stock_items: [
- { stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 75 },
- ],
+ stock_levels: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 75 }],
})
+
// endregion:example
export { variant }
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index 60144e1026..6ec57496e1 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -205,7 +205,7 @@ import type {
SetupCountries,
SetupParams,
SetupStatus,
- StockItemUpdateParams,
+ StockLevelUpdateParams,
StockLocationCreateParams,
StockLocationUpdateParams,
StockTransferCreateParams,
@@ -290,7 +290,7 @@ import type {
Return,
ReturnReason,
Role,
- StockItem,
+ StockLevel,
StockLocation,
StockTransfer,
Store,
@@ -3834,12 +3834,12 @@ export class AdminClient {
// Stock Items
// ============================================
- readonly stockItems = {
+ readonly stockLevels = {
list: (
params?: ListParams & Record<string, unknown>,
options?: RequestOptions,
- ): Promise<PaginatedResponse<StockItem>> =>
- this.request<PaginatedResponse<StockItem>>('GET', '/stock_items', {
+ ): Promise<PaginatedResponse<StockLevel>> =>
+ this.request<PaginatedResponse<StockLevel>>('GET', '/stock_levels', {
...options,
params: params ? transformListParams(params) : undefined,
}),
@@ -3848,21 +3848,21 @@ export class AdminClient {
id: string,
params?: { expand?: string[] },
options?: RequestOptions,
- ): Promise<StockItem> =>
- this.request<StockItem>('GET', `/stock_items/${id}`, {
+ ): Promise<StockLevel> =>
+ this.request<StockLevel>('GET', `/stock_levels/${id}`, {
...options,
params: getParams(params),
}),
update: (
id: string,
- params: StockItemUpdateParams,
+ params: StockLevelUpdateParams,
options?: RequestOptions,
- ): Promise<StockItem> =>
- this.request<StockItem>('PATCH', `/stock_items/${id}`, { ...options, body: params }),
+ ): Promise<StockLevel> =>
+ this.request<StockLevel>('PATCH', `/stock_levels/${id}`, { ...options, body: params }),
delete: (id: string, options?: RequestOptions): Promise<void> =>
- this.request<void>('DELETE', `/stock_items/${id}`, options),
+ this.request<void>('DELETE', `/stock_levels/${id}`, options),
}
// ============================================
diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.ts
index 92d338243f..da9525fee6 100644
--- a/packages/admin-sdk/src/params.ts
+++ b/packages/admin-sdk/src/params.ts
@@ -658,7 +658,7 @@ export interface ProductVariantInput {
options?: VariantOptionPair[]
/** Per-currency prices. Upserted by currency. */
prices?: VariantPrice[]
- stock_items?: VariantStockItem[]
+ stock_levels?: VariantStockLevel[]
}
export interface CategoryCreateParams {
@@ -819,7 +819,7 @@ export interface VariantPrice {
compare_at_amount?: string | number | null
}
-export interface VariantStockItem {
+export interface VariantStockLevel {
stock_location_id: string
count_on_hand: number
backorderable?: boolean
@@ -851,7 +851,7 @@ export interface VariantCreateParams {
options: [VariantOptionPair, ...VariantOptionPair[]]
/** Per-currency prices. Upserted by currency. */
prices?: VariantPrice[]
- stock_items?: VariantStockItem[]
+ stock_levels?: VariantStockLevel[]
}
export interface VariantUpdateParams {
@@ -876,7 +876,7 @@ export interface VariantUpdateParams {
options?: VariantOptionPair[]
/** Per-currency prices. Upserted by currency. */
prices?: VariantPrice[]
- stock_items?: VariantStockItem[]
+ stock_levels?: VariantStockLevel[]
}
export interface CustomFieldCreateParams {
@@ -1106,7 +1106,7 @@ export interface StockLocationUpdateParams {
pickup_instructions?: string | null
}
-export interface StockItemUpdateParams {
+export interface StockLevelUpdateParams {
count_on_hand?: number
backorderable?: boolean
metadata?: Record<string, unknown>
diff --git a/packages/admin-sdk/src/types/index.ts b/packages/admin-sdk/src/types/index.ts
index 7589e0a620..ae64fe9a93 100644
--- a/packages/admin-sdk/src/types/index.ts
+++ b/packages/admin-sdk/src/types/index.ts
@@ -88,7 +88,7 @@ export type { default as ReturnReason } from './generated/ReturnReason'
export type { default as Role } from './generated/Role'
export type { default as SetupTask } from './generated/SetupTask'
export type { default as State } from './generated/State'
-export type { default as StockItem } from './generated/StockItem'
+export type { default as StockLevel } from './generated/StockLevel'
export type { default as StockLocation } from './generated/StockLocation'
export type { default as StockReservation } from './generated/StockReservation'
export type { default as StockTransfer } from './generated/StockTransfer'
diff --git a/packages/admin-sdk/tests/read-only-resources.test.ts b/packages/admin-sdk/tests/read-only-resources.test.ts
index 2cb25fe520..43280d79bb 100644
--- a/packages/admin-sdk/tests/read-only-resources.test.ts
+++ b/packages/admin-sdk/tests/read-only-resources.test.ts
@@ -145,11 +145,11 @@ describe('variants', () => {
)
const res = await createTestClient().variants.get('variant_abc123', {
- expand: ['stock_items'],
+ expand: ['stock_levels'],
})
expect(res.id).toBe('variant_abc123')
- expect(url!.searchParams.get('expand')).toBe('stock_items')
+ expect(url!.searchParams.get('expand')).toBe('stock_levels')
})
})
})
diff --git a/packages/admin-sdk/tests/stock.test.ts b/packages/admin-sdk/tests/stock.test.ts
index abc531efd5..f3c47c96fa 100644
--- a/packages/admin-sdk/tests/stock.test.ts
+++ b/packages/admin-sdk/tests/stock.test.ts
@@ -12,7 +12,7 @@ const sampleStockLocation = {
updated_at: '2026-05-01T00:00:00Z',
}
-const sampleStockItem = {
+const sampleStockLevel = {
id: 'si_abc123',
count_on_hand: 42,
backorderable: false,
@@ -73,11 +73,11 @@ describe('stockLocations', () => {
)
const res = await createTestClient().stockLocations.get('sl_abc123', {
- expand: ['stock_items'],
+ expand: ['stock_levels'],
})
expect(res.id).toBe('sl_abc123')
- expect(url!.searchParams.get('expand')).toBe('stock_items')
+ expect(url!.searchParams.get('expand')).toBe('stock_levels')
})
})
@@ -126,16 +126,16 @@ describe('stockLocations', () => {
})
})
-describe('stockItems', () => {
+describe('stockLevels', () => {
describe('list', () => {
- it('GETs /stock_items and returns paginated data', async () => {
+ it('GETs /stock_levels and returns paginated data', async () => {
server.use(
- http.get(`${API_PREFIX}/stock_items`, () =>
- HttpResponse.json(paginated([sampleStockItem])),
+ http.get(`${API_PREFIX}/stock_levels`, () =>
+ HttpResponse.json(paginated([sampleStockLevel])),
),
)
- const res = await createTestClient().stockItems.list()
+ const res = await createTestClient().stockLevels.list()
expect(res.data).toHaveLength(1)
expect(res.data[0]?.id).toBe('si_abc123')
@@ -144,13 +144,13 @@ describe('stockItems', () => {
it('wraps Ransack predicates via transformListParams', async () => {
let url: URL | null = null
server.use(
- http.get(`${API_PREFIX}/stock_items`, ({ request }) => {
+ http.get(`${API_PREFIX}/stock_levels`, ({ request }) => {
url = new URL(request.url)
return HttpResponse.json(paginated([]))
}),
)
- await createTestClient().stockItems.list({
+ await createTestClient().stockLevels.list({
stock_location_id_eq: 'sl_abc123',
variant_id_eq: 'variant_1',
})
@@ -161,16 +161,16 @@ describe('stockItems', () => {
})
describe('get', () => {
- it('GETs /stock_items/:id and forwards expand params', async () => {
+ it('GETs /stock_levels/:id and forwards expand params', async () => {
let url: URL | null = null
server.use(
- http.get(`${API_PREFIX}/stock_items/si_abc123`, ({ request }) => {
+ http.get(`${API_PREFIX}/stock_levels/si_abc123`, ({ request }) => {
url = new URL(request.url)
- return HttpResponse.json(sampleStockItem)
+ return HttpResponse.json(sampleStockLevel)
}),
)
- const res = await createTestClient().stockItems.get('si_abc123', { expand: ['variant'] })
+ const res = await createTestClient().stockLevels.get('si_abc123', { expand: ['variant'] })
expect(res.id).toBe('si_abc123')
expect(url!.searchParams.get('expand')).toBe('variant')
@@ -181,28 +181,28 @@ describe('stockItems', () => {
it('PATCHes the update body verbatim', async () => {
let body: Record<string, unknown> | null = null
server.use(
- http.patch(`${API_PREFIX}/stock_items/si_abc123`, async ({ request }) => {
+ http.patch(`${API_PREFIX}/stock_levels/si_abc123`, async ({ request }) => {
body = (await request.json()) as Record<string, unknown>
- return HttpResponse.json({ ...sampleStockItem, count_on_hand: 100 })
+ return HttpResponse.json({ ...sampleStockLevel, count_on_hand: 100 })
}),
)
- const res = await createTestClient().stockItems.update('si_abc123', { count_on_hand: 100 })
+ const res = await createTestClient().stockLevels.update('si_abc123', { count_on_hand: 100 })
expect(body).toEqual({ count_on_hand: 100 })
expect(res.count_on_hand).toBe(100)
})
- it('DELETEs /stock_items/:id', async () => {
+ it('DELETEs /stock_levels/:id', async () => {
let hit = false
server.use(
- http.delete(`${API_PREFIX}/stock_items/si_abc123`, () => {
+ http.delete(`${API_PREFIX}/stock_levels/si_abc123`, () => {
hit = true
return new HttpResponse(null, { status: 204 })
}),
)
- await expect(createTestClient().stockItems.delete('si_abc123')).resolves.toBeUndefined()
+ await expect(createTestClient().stockLevels.delete('si_abc123')).resolves.toBeUndefined()
expect(hit).toBe(true)
})
})
diff --git a/packages/dashboard-core/src/lib/permissions.ts b/packages/dashboard-core/src/lib/permissions.ts
index d7c06c7430..81edfd1935 100644
--- a/packages/dashboard-core/src/lib/permissions.ts
+++ b/packages/dashboard-core/src/lib/permissions.ts
@@ -44,7 +44,7 @@ export const Subject = {
/** @deprecated Use Subject.DeliveryMethod — removed in Spree 6.1. */
ShippingMethod: 'Spree::ShippingMethod',
StockLocation: 'Spree::StockLocation',
- StockItem: 'Spree::StockItem',
+ StockLevel: 'Spree::StockLevel',
StockTransfer: 'Spree::StockTransfer',
PriceList: 'Spree::PriceList',
PriceRule: 'Spree::PriceRule',
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index 715e6c798b..08cb2950ec 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -64,7 +64,7 @@ const BOOTSTRAP_RUBY = [
// order-creation tests can add it to a draft order without the
// +"Quantity not available"+ validation kicking in.
`default_location = s.default_stock_location`,
- `product.variants_including_master.each { |v| default_location.stock_items.where(variant: v).first_or_create!.update!(count_on_hand: 100, backorderable: true) }`,
+ `product.variants_including_master.each { |v| default_location.stock_levels.where(variant: v).first_or_create!.update!(count_on_hand: 100, backorderable: true) }`,
// Disjoint product fixtures for products-bulk.spec.ts. Each test owns its
// own pair (A/B → status, C/D → categories, E/F → tags, G/H → delete,
// I → row-action clone/delete) so the serial suite can mutate them in any
diff --git a/packages/dashboard/e2e/products-prices-inventory.spec.ts b/packages/dashboard/e2e/products-prices-inventory.spec.ts
index ddf4341bfa..4f93c76e63 100644
--- a/packages/dashboard/e2e/products-prices-inventory.spec.ts
+++ b/packages/dashboard/e2e/products-prices-inventory.spec.ts
@@ -210,7 +210,7 @@ test.describe('product inventory — multi-variant', () => {
// Create a second stock location first — the test then verifies the
// inventory grid renders editable cells for it on a fresh product
// (previously it only rendered rows for locations with a persisted
- // stock_item, so the new location showed up without inputs).
+ // stock_level, so the new location showed up without inputs).
const locationName = `E2E Warehouse ${Date.now()}`
await createStockLocation(page, creds.store_id, locationName)
diff --git a/packages/dashboard/src/components/spree/products/inventory-section.tsx b/packages/dashboard/src/components/spree/products/inventory-section.tsx
index e9763d6971..eaac925fce 100644
--- a/packages/dashboard/src/components/spree/products/inventory-section.tsx
+++ b/packages/dashboard/src/components/spree/products/inventory-section.tsx
@@ -13,7 +13,7 @@ import { type UseFormReturn, useWatch } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { useOptionTypes } from '../../../hooks/use-option-types'
import { useStockLocations } from '../../../hooks/use-stock-locations'
-import type { ProductFormValues, StockItemFormValues } from '../../../schemas/product'
+import type { ProductFormValues, StockLevelFormValues } from '../../../schemas/product'
import { composeOptionsText } from './variants-matrix'
interface InventoryRow {
@@ -76,11 +76,11 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
})
}
// Render one row per (variant × location), regardless of whether a
- // stock_item exists in form state. Mirrors the pricing editor's
+ // stock_level exists in form state. Mirrors the pricing editor's
// (variant × currency) projection. Missing entries display 0/false and
- // are created on first edit via findOrCreateStockItem below.
+ // are created on first edit via findOrCreateStockLevel below.
stockLocations.forEach((loc) => {
- const existing = (variant.stock_items ?? []).find((si) => si.stock_location_id === loc.id)
+ const existing = (variant.stock_levels ?? []).find((si) => si.stock_location_id === loc.id)
out.push({
id: `${variantIndex}.${loc.id}`,
kind: 'item',
@@ -95,10 +95,10 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
return out
}, [variants, stockLocations, hasMultipleVariants, optionTypes, t])
- // Find-or-create the stock_item entry for (variantIndex, stockLocationId)
+ // Find-or-create the stock_level entry for (variantIndex, stockLocationId)
// and patch the given field. Uses form.setValue with the full updated
- // stock_items array so RHF treats this as one atomic edit per cell.
- const patchStockItem = useCallback(
+ // stock_levels array so RHF treats this as one atomic edit per cell.
+ const patchStockLevel = useCallback(
(
variantIndex: number,
stockLocationId: string,
@@ -106,9 +106,9 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
field: 'count_on_hand' | 'backorderable',
next: number | boolean,
) => {
- const current = form.getValues(`variants.${variantIndex}.stock_items`) ?? []
+ const current = form.getValues(`variants.${variantIndex}.stock_levels`) ?? []
const existingIdx = current.findIndex((si) => si.stock_location_id === stockLocationId)
- const nextItems: StockItemFormValues[] = [...current]
+ const nextItems: StockLevelFormValues[] = [...current]
if (existingIdx === -1) {
nextItems.push({
stock_location_id: stockLocationId,
@@ -125,7 +125,7 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
: { backorderable: next as boolean }),
}
}
- form.setValue(`variants.${variantIndex}.stock_items`, nextItems, { shouldDirty: true })
+ form.setValue(`variants.${variantIndex}.stock_levels`, nextItems, { shouldDirty: true })
},
[form],
)
@@ -173,7 +173,7 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
coords={coords}
value={value}
onChange={(next) =>
- patchStockItem(
+ patchStockLevel(
r.variantIndex,
r.stockLocationId as string,
r.stockLocationName as string,
@@ -201,7 +201,7 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
coords={coords}
value={r.backorderable ?? false}
onChange={(next) =>
- patchStockItem(
+ patchStockLevel(
r.variantIndex,
r.stockLocationId as string,
r.stockLocationName as string,
@@ -217,7 +217,7 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {
},
},
],
- [patchStockItem, storeId, t],
+ [patchStockLevel, storeId, t],
)
if (rows.length === 0) {
diff --git a/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx b/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx
index 0413ded670..493ccb7376 100644
--- a/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx
+++ b/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx
@@ -55,7 +55,7 @@ export function VariantEditSheet({ form, variantIndex, open, onOpenChange }: Pro
//
// Deep-clone via structuredClone — `form.getValues` returns a reference
// to RHF's internal field state, and the inline cell editors mutate
- // nested arrays (prices, stock_items) in place. Without the clone, Cancel
+ // nested arrays (prices, stock_levels) in place. Without the clone, Cancel
// would write back the already-edited object.
//
// We also stash the variant's `id` (for persisted rows). The sheet is
diff --git a/packages/dashboard/src/components/spree/products/variants-matrix.ts b/packages/dashboard/src/components/spree/products/variants-matrix.ts
index d9354e6a43..e31fb46842 100644
--- a/packages/dashboard/src/components/spree/products/variants-matrix.ts
+++ b/packages/dashboard/src/components/spree/products/variants-matrix.ts
@@ -78,7 +78,7 @@ export function optionsKey(options: { name: string; value: string }[]): string {
}
export interface ReconcileResult {
- // Carries persisted id/sku/prices/stock_items forward for matched combos,
+ // Carries persisted id/sku/prices/stock_levels forward for matched combos,
// and stamps new entries with defaults. Position is the array index.
next: VariantFormValues[]
// Options-keys of variants that no longer match any generated combination
@@ -99,7 +99,7 @@ export interface ReconcileResult {
// to show a confirm-before-drop banner; "Keep all" dismisses the banner
// without changing the array, "Remove" filters them out.
//
-// Blank variants ship with empty `prices` + `stock_items`. The inventory
+// Blank variants ship with empty `prices` + `stock_levels`. The inventory
// grid renders editable rows for every (variant × location) and creates
// entries on first edit; the pricing editor does the same per currency.
// No pre-seeding here means the payload stays clean — only locations the
@@ -156,7 +156,7 @@ export function reconcileVariants(
// Does this variant carry merchant data we'd lose if dropped?
//
// Server-propagated default variants come back with `weight: 0` (NOT NULL
-// column with default) and zero-count stock_items for every active location.
+// column with default) and zero-count stock_levels for every active location.
// Treat those zero/default sentinels as "no data" — only truthy fields
// count the row as carrying intent. Without this, every saved
// single-variant product would be treated as an orphan on upgrade and the
@@ -173,7 +173,7 @@ function variantHasMerchantData(v: VariantFormValues): boolean {
!!v.sku ||
!!v.barcode ||
(v.prices?.length ?? 0) > 0 ||
- (v.stock_items?.some((s) => (s.count_on_hand ?? 0) > 0) ?? false) ||
+ (v.stock_levels?.some((s) => (s.count_on_hand ?? 0) > 0) ?? false) ||
(v.weight ?? 0) > 0 ||
(v.height ?? 0) > 0 ||
(v.width ?? 0) > 0 ||
@@ -199,7 +199,7 @@ export function blankVariant(
track_inventory: true,
tax_category_id: null,
prices: [],
- stock_items: [],
+ stock_levels: [],
}
}
diff --git a/packages/dashboard/src/components/spree/products/variants-section.tsx b/packages/dashboard/src/components/spree/products/variants-section.tsx
index 436a745360..f71188d2e4 100644
--- a/packages/dashboard/src/components/spree/products/variants-section.tsx
+++ b/packages/dashboard/src/components/spree/products/variants-section.tsx
@@ -206,7 +206,7 @@ export function VariantsSection({ form, seedFromType = false }: Props) {
// No options selected — drop all option-bearing variants down to a
// single default-variant row so the product remains purchasable. Keep
// a persisted id when possible so the existing default is reused, and
- // carry stock_items forward. The inventory grid fills any gaps for
+ // carry stock_levels forward. The inventory grid fills any gaps for
// locations the default doesn't already cover (find-or-create on edit).
const carry = existing[0]
const defaultRow: VariantFormValues = {
@@ -224,7 +224,7 @@ export function VariantsSection({ form, seedFromType = false }: Props) {
track_inventory: carry?.track_inventory ?? true,
tax_category_id: carry?.tax_category_id ?? null,
prices: carry?.prices ?? [],
- stock_items: carry?.stock_items ?? [],
+ stock_levels: carry?.stock_levels ?? [],
}
form.setValue('variants', [defaultRow], { shouldDirty: true })
setOrphanedKeys([])
diff --git a/packages/dashboard/src/hooks/use-product.ts b/packages/dashboard/src/hooks/use-product.ts
index 9ff2e9f412..6cd9946c81 100644
--- a/packages/dashboard/src/hooks/use-product.ts
+++ b/packages/dashboard/src/hooks/use-product.ts
@@ -16,12 +16,12 @@ export function useProduct(id: string) {
expand: [
'default_variant',
'default_variant.prices',
- 'default_variant.stock_items',
- 'default_variant.stock_items.stock_location',
+ 'default_variant.stock_levels',
+ 'default_variant.stock_levels.stock_location',
'variants',
'variants.prices',
- 'variants.stock_items',
- 'variants.stock_items.stock_location',
+ 'variants.stock_levels',
+ 'variants.stock_levels.stock_location',
'option_types',
'categories',
'collections',
diff --git a/packages/dashboard/src/hooks/use-stock-coverage.test.ts b/packages/dashboard/src/hooks/use-stock-coverage.test.ts
index 7711d22966..48ce23eb6f 100644
--- a/packages/dashboard/src/hooks/use-stock-coverage.test.ts
+++ b/packages/dashboard/src/hooks/use-stock-coverage.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
-import { type CoverageStockItem, computeStockCoverage } from './use-stock-coverage'
+import { type CoverageStockLevel, computeStockCoverage } from './use-stock-coverage'
-function stockItem(overrides: Partial<CoverageStockItem>): CoverageStockItem {
+function stockLevel(overrides: Partial<CoverageStockLevel>): CoverageStockLevel {
return {
stock_location_id: 'sloc_1',
variant_id: 'variant_1',
@@ -15,8 +15,8 @@ describe('computeStockCoverage', () => {
it('covers a location holding enough of every demanded variant', () => {
const coverage = computeStockCoverage(
[
- stockItem({ variant_id: 'variant_1', available_count: 5 }),
- stockItem({ variant_id: 'variant_2', available_count: 2 }),
+ stockLevel({ variant_id: 'variant_1', available_count: 5 }),
+ stockLevel({ variant_id: 'variant_2', available_count: 2 }),
],
[
{ variantId: 'variant_1', quantity: 3 },
@@ -30,8 +30,8 @@ describe('computeStockCoverage', () => {
it('does not cover a location short on one variant', () => {
const coverage = computeStockCoverage(
[
- stockItem({ variant_id: 'variant_1', available_count: 5 }),
- stockItem({ variant_id: 'variant_2', available_count: 1 }),
+ stockLevel({ variant_id: 'variant_1', available_count: 5 }),
+ stockLevel({ variant_id: 'variant_2', available_count: 1 }),
],
[
{ variantId: 'variant_1', quantity: 1 },
@@ -46,7 +46,7 @@ describe('computeStockCoverage', () => {
// transfer, so an empty shelf still counts as covered.
it('treats a backorderable row as unlimited', () => {
const coverage = computeStockCoverage(
- [stockItem({ available_count: 0, backorderable: true })],
+ [stockLevel({ available_count: 0, backorderable: true })],
[{ variantId: 'variant_1', quantity: 99 }],
)
@@ -55,7 +55,7 @@ describe('computeStockCoverage', () => {
it('does not cover a location missing a variant entirely', () => {
const coverage = computeStockCoverage(
- [stockItem({ stock_location_id: 'sloc_1', variant_id: 'variant_1', available_count: 5 })],
+ [stockLevel({ stock_location_id: 'sloc_1', variant_id: 'variant_1', available_count: 5 })],
[
{ variantId: 'variant_1', quantity: 1 },
{ variantId: 'variant_2', quantity: 1 },
@@ -68,8 +68,8 @@ describe('computeStockCoverage', () => {
it('keeps locations independent of one another', () => {
const coverage = computeStockCoverage(
[
- stockItem({ stock_location_id: 'sloc_1', available_count: 10 }),
- stockItem({ stock_location_id: 'sloc_2', available_count: 0 }),
+ stockLevel({ stock_location_id: 'sloc_1', available_count: 10 }),
+ stockLevel({ stock_location_id: 'sloc_2', available_count: 0 }),
],
[{ variantId: 'variant_1', quantity: 4 }],
)
diff --git a/packages/dashboard/src/hooks/use-stock-coverage.ts b/packages/dashboard/src/hooks/use-stock-coverage.ts
index 9dae1d6f53..31b2859451 100644
--- a/packages/dashboard/src/hooks/use-stock-coverage.ts
+++ b/packages/dashboard/src/hooks/use-stock-coverage.ts
@@ -27,10 +27,10 @@ export function useStockCoverage(demands: VariantDemand[], enabled = true) {
const variantIds = demands.map((demand) => demand.variantId).sort()
return useQuery({
- queryKey: useResourceKey('stock-items', 'coverage', variantIds),
+ queryKey: useResourceKey('stock-levels', 'coverage', variantIds),
enabled: enabled && variantIds.length > 0,
queryFn: async (): Promise<StockCoverage> => {
- const response = await adminClient.stockItems.list({
+ const response = await adminClient.stockLevels.list({
variant_id_in: variantIds,
// A variant can exist at every location, so the ceiling is
// variants × locations. The API caps `limit` at 100; merchants with
@@ -44,8 +44,8 @@ export function useStockCoverage(demands: VariantDemand[], enabled = true) {
})
}
-/** The stock-item fields the coverage computation reads. */
-export interface CoverageStockItem {
+/** The stock-level fields the coverage computation reads. */
+export interface CoverageStockLevel {
stock_location_id?: string | null
variant_id?: string | null
available_count: number
@@ -62,21 +62,21 @@ export interface CoverageStockItem {
* a transfer stays selectable.
*/
export function computeStockCoverage(
- stockItems: CoverageStockItem[],
+ stockLevels: CoverageStockLevel[],
demands: VariantDemand[],
): StockCoverage {
const availabilityByLocation = new Map<string, Map<string, number>>()
- for (const stockItem of stockItems) {
- if (!stockItem.stock_location_id || !stockItem.variant_id) continue
+ for (const stockLevel of stockLevels) {
+ if (!stockLevel.stock_location_id || !stockLevel.variant_id) continue
const perVariant =
- availabilityByLocation.get(stockItem.stock_location_id) ?? new Map<string, number>()
+ availabilityByLocation.get(stockLevel.stock_location_id) ?? new Map<string, number>()
perVariant.set(
- stockItem.variant_id,
- stockItem.backorderable ? Number.POSITIVE_INFINITY : stockItem.available_count,
+ stockLevel.variant_id,
+ stockLevel.backorderable ? Number.POSITIVE_INFINITY : stockLevel.available_count,
)
- availabilityByLocation.set(stockItem.stock_location_id, perVariant)
+ availabilityByLocation.set(stockLevel.stock_location_id, perVariant)
}
const coverage: StockCoverage = new Map()
diff --git a/packages/dashboard/src/hooks/use-stock-levels.ts b/packages/dashboard/src/hooks/use-stock-levels.ts
index 13e66650e6..a715d961e8 100644
--- a/packages/dashboard/src/hooks/use-stock-levels.ts
+++ b/packages/dashboard/src/hooks/use-stock-levels.ts
@@ -1,4 +1,4 @@
-import type { StockItem, StockItemUpdateParams } from '@spree/admin-sdk'
+import type { StockLevel, StockLevelUpdateParams } from '@spree/admin-sdk'
import {
adminClient,
useResourceKey,
@@ -8,18 +8,18 @@ import {
import { type QueryKey, useQuery, useQueryClient } from '@tanstack/react-query'
import i18n from 'i18next'
-interface UseStockItemsParams {
+interface UseStockLevelsParams {
page?: number
limit?: number
stock_location_id_eq?: string
variant_sku_or_variant_product_name_cont?: string
}
-export function useStockItems(params: UseStockItemsParams = {}) {
+export function useStockLevels(params: UseStockLevelsParams = {}) {
return useQuery({
- queryKey: useResourceKey('stock-items', params),
+ queryKey: useResourceKey('stock-levels', params),
queryFn: () =>
- adminClient.stockItems.list({
+ adminClient.stockLevels.list({
page: params.page ?? 1,
limit: params.limit ?? 25,
// The stock-at-location panel renders the variant's product name +
@@ -38,26 +38,26 @@ export function useStockItems(params: UseStockItemsParams = {}) {
})
}
-export function useUpdateStockItem(id: string, extraInvalidate: QueryKey[] = []) {
- return useResourceMutation<StockItem, Error, StockItemUpdateParams>({
- mutationFn: (params) => adminClient.stockItems.update(id, params),
- invalidate: [['stock-items'], ['stock-items', id], ...extraInvalidate],
- successMessage: i18n.t('admin.stock_items.messages.stock_updated'),
+export function useUpdateStockLevel(id: string, extraInvalidate: QueryKey[] = []) {
+ return useResourceMutation<StockLevel, Error, StockLevelUpdateParams>({
+ mutationFn: (params) => adminClient.stockLevels.update(id, params),
+ invalidate: [['stock-levels'], ['stock-levels', id], ...extraInvalidate],
+ successMessage: i18n.t('admin.stock_levels.messages.stock_updated'),
errorMessage: i18n.t('admin.errors.failed_to_update'),
})
}
-export function useDeleteStockItem() {
+export function useDeleteStockLevel() {
const queryClient = useQueryClient()
const buildKey = useResourceKeyBuilder()
return useResourceMutation<void, Error, string>({
- mutationFn: (id) => adminClient.stockItems.delete(id),
- invalidate: [['stock-items']],
- successMessage: i18n.t('admin.stock_items.messages.stock_item_deleted'),
+ mutationFn: (id) => adminClient.stockLevels.delete(id),
+ invalidate: [['stock-levels']],
+ successMessage: i18n.t('admin.stock_levels.messages.stock_level_deleted'),
errorMessage: i18n.t('admin.errors.failed_to_delete'),
onSuccess: (_data, id) => {
- queryClient.removeQueries({ queryKey: buildKey('stock-items', id) })
+ queryClient.removeQueries({ queryKey: buildKey('stock-levels', id) })
},
})
}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index d0dae9dd5b..fb847e897f 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -2982,7 +2982,7 @@
"refund": "استرداد",
"report": "تقرير",
"return": "يعود",
- "stock_item": "عنصر المخزون",
+ "stock_level": "مستوى المخزون",
"stock_movement": "حركة الأسهم",
"stock_reservation": "Stock reservation",
"stock_transfer": "نقل المخزون",
@@ -3818,9 +3818,9 @@
"roles_required": "اختر دورًا واحدًا على الأقل"
}
},
- "stock_items": {
+ "stock_levels": {
"messages": {
- "stock_item_deleted": "تم حذف عنصر المخزون",
+ "stock_level_deleted": "تم حذف مستوى المخزون",
"stock_updated": "تم تحديث المخزون"
}
},
@@ -3856,9 +3856,9 @@
},
"search_placeholder": "البحث بالاسم…",
"section_pickup": "يلتقط",
- "stock_items": {
- "empty": "لا توجد عناصر المخزون في هذا الموقع حتى الآن.",
- "empty_search": "لا توجد عناصر مخزون تطابق بحثك.",
+ "stock_levels": {
+ "empty": "لا توجد مستويات مخزون في هذا الموقع حتى الآن.",
+ "empty_search": "لا توجد مستويات مخزون تطابق بحثك.",
"help": "اضبط الأعداد المتاحة والقابلة للطلب الخلفي لكل متغير.",
"low_stock_marker": "مخزون منخفض",
"search_placeholder": "ابحث عن SKU أو المنتج…",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 2a5311b427..9d150a0e73 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -2972,7 +2972,7 @@
"refund": "Erstattung",
"report": "Bericht",
"return": "Rücksendung",
- "stock_item": "Bestandsartikel",
+ "stock_level": "Lagerbestand",
"stock_movement": "Bestandsbewegung",
"stock_reservation": "Bestandsreservierung",
"stock_transfer": "Bestandsübertragung",
@@ -3802,9 +3802,9 @@
"roles_required": "Wählen Sie mindestens eine Rolle"
}
},
- "stock_items": {
+ "stock_levels": {
"messages": {
- "stock_item_deleted": "Bestandsposition gelöscht",
+ "stock_level_deleted": "Lagerbestand gelöscht",
"stock_updated": "Bestand aktualisiert"
}
},
@@ -3840,9 +3840,9 @@
},
"search_placeholder": "Nach Name suchen…",
"section_pickup": "Abholung",
- "stock_items": {
- "empty": "An diesem Standort sind noch keine Bestandsartikel vorhanden.",
- "empty_search": "Keine Bestandsartikel entsprechen Ihrer Suche.",
+ "stock_levels": {
+ "empty": "An diesem Standort sind noch keine Lagerbestände vorhanden.",
+ "empty_search": "Keine Lagerbestände entsprechen Ihrer Suche.",
"help": "Passen Sie die verfügbaren und nachbestellbaren Mengen pro Variante an.",
"low_stock_marker": "niedriger Bestand",
"search_placeholder": "SKU oder Produkt suchen…",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index e2c35f6715..124c05bb16 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -2972,7 +2972,7 @@
"refund": "Refund",
"report": "Report",
"return": "Return",
- "stock_item": "Stock item",
+ "stock_level": "Stock level",
"stock_movement": "Stock movement",
"stock_reservation": "Stock reservation",
"stock_transfer": "Stock transfer",
@@ -3802,9 +3802,9 @@
"roles_required": "Pick at least one role"
}
},
- "stock_items": {
+ "stock_levels": {
"messages": {
- "stock_item_deleted": "Stock item deleted",
+ "stock_level_deleted": "Stock level deleted",
"stock_updated": "Stock updated"
}
},
@@ -3840,9 +3840,9 @@
},
"search_placeholder": "Search by name…",
"section_pickup": "Pickup",
- "stock_items": {
- "empty": "No stock items at this location yet.",
- "empty_search": "No stock items match your search.",
+ "stock_levels": {
+ "empty": "No stock levels at this location yet.",
+ "empty_search": "No stock levels match your search.",
"help": "Adjust on-hand and backorderable counts per variant.",
"low_stock_marker": "low stock",
"search_placeholder": "Search SKU or product…",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index d674c9ca8b..b3ef82cdb0 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -2972,7 +2972,7 @@
"refund": "Remboursement",
"report": "Rapport",
"return": "Retour",
- "stock_item": "Article en stock",
+ "stock_level": "Niveau de stock",
"stock_movement": "Mouvement de stock",
"stock_reservation": "Réservation de stock",
"stock_transfer": "Transfert de stock",
@@ -3802,9 +3802,9 @@
"roles_required": "Choisissez au moins un rôle"
}
},
- "stock_items": {
+ "stock_levels": {
"messages": {
- "stock_item_deleted": "Article en stock supprimé",
+ "stock_level_deleted": "Niveau de stock supprimé",
"stock_updated": "Stock mis à jour"
}
},
@@ -3840,9 +3840,9 @@
},
"search_placeholder": "Rechercher par nom…",
"section_pickup": "Retrait",
- "stock_items": {
- "empty": "Aucun article en stock à cet emplacement pour le moment.",
- "empty_search": "Aucun article en stock ne correspond à votre recherche.",
+ "stock_levels": {
+ "empty": "Aucun niveau de stock à cet emplacement pour le moment.",
+ "empty_search": "Aucun niveau de stock ne correspond à votre recherche.",
"help": "Ajustez les quantités disponibles et en réassort par variante.",
"low_stock_marker": "stock faible",
"search_placeholder": "Rechercher un SKU ou un produit…",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index 80d7dab349..0f9c766a70 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -3010,7 +3010,7 @@
"refund": "Zwrot środków",
"report": "Raport",
"return": "Zwrot",
- "stock_item": "Pozycja magazynowa",
+ "stock_level": "Stan magazynowy",
"stock_movement": "Ruch magazynowy",
"stock_reservation": "Rezerwacja magazynowa",
"stock_transfer": "Transfer magazynowy",
@@ -3856,9 +3856,9 @@
"roles_required": "Wybierz co najmniej jedną rolę"
}
},
- "stock_items": {
+ "stock_levels": {
"messages": {
- "stock_item_deleted": "Usunięto pozycję magazynową",
+ "stock_level_deleted": "Usunięto stan magazynowy",
"stock_updated": "Zaktualizowano stan magazynowy"
}
},
@@ -3894,9 +3894,9 @@
},
"search_placeholder": "Szukaj według nazwy…",
"section_pickup": "Odbiór",
- "stock_items": {
- "empty": "Brak zapasów w tej lokalizacji.",
- "empty_search": "Żadne zapasy nie pasują do wyszukiwania.",
+ "stock_levels": {
+ "empty": "Brak stanów magazynowych w tej lokalizacji.",
+ "empty_search": "Żadne stany magazynowe nie pasują do wyszukiwania.",
"help": "Dostosuj liczbę dostępnych i możliwych do zamówienia z opóźnieniem dla każdego wariantu.",
"low_stock_marker": "niski stan",
"search_placeholder": "Szukaj SKU lub produktu…",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 3749090db9..9dff5852ff 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -2968,7 +2968,7 @@
"refund": "退款",
"report": "报表",
"return": "退货",
- "stock_item": "库存项",
+ "stock_level": "库存水平",
"stock_movement": "库存变动",
"stock_reservation": "库存预留",
"stock_transfer": "库存调拨",
@@ -3798,9 +3798,9 @@
"roles_required": "请至少选择一个角色"
}
},
- "stock_items": {
+ "stock_levels": {
"messages": {
- "stock_item_deleted": "库存项已删除",
+ "stock_level_deleted": "库存水平已删除",
"stock_updated": "库存已更新"
}
},
@@ -3836,9 +3836,9 @@
},
"search_placeholder": "按名称搜索…",
"section_pickup": "自提",
- "stock_items": {
- "empty": "此地点暂无库存项。",
- "empty_search": "没有与搜索匹配的库存项。",
+ "stock_levels": {
+ "empty": "此地点暂无库存水平。",
+ "empty_search": "没有与搜索匹配的库存水平。",
"help": "按变体调整在库数量和可缺货预订数量。",
"low_stock_marker": "库存不足",
"search_placeholder": "搜索 SKU 或商品…",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
index 21d5e30e29..db99634f37 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
@@ -97,7 +97,7 @@ function variantToFormValues(variant: Variant, position: number): VariantFormVal
amount: p.amount != null ? String(p.amount) : '',
compare_at_amount: p.compare_at_amount != null ? String(p.compare_at_amount) : null,
})),
- stock_items: (variant.stock_items ?? []).map((si) => ({
+ stock_levels: (variant.stock_levels ?? []).map((si) => ({
id: si.id,
stock_location_id: si.stock_location_id ?? si.stock_location?.id ?? '',
stock_location_name:
@@ -223,8 +223,8 @@ export function variantToWirePayload(v: VariantFormValues, index: number) {
// the canonical API. So no normalization here — re-normalizing a canonical
// value under a comma-decimal locale would mangle it (`34.56` → `3456`).
if (v.prices != null) payload.prices = v.prices
- if (v.stock_items?.length) {
- payload.stock_items = v.stock_items.map(({ stock_location_name, ...rest }) => rest)
+ if (v.stock_levels?.length) {
+ payload.stock_levels = v.stock_levels.map(({ stock_location_name, ...rest }) => rest)
}
return payload
}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx
index 6c2340347c..652f734544 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx
@@ -57,7 +57,7 @@ function NewProductPage() {
// Strip the placeholder default variant if the merchant didn't touch it.
// Spree::Product#variants= auto-creates the canonical default variant
// server-side when none is provided. Any variant with options, SKU,
- // prices, or stock_items survives as merchant intent.
+ // prices, or stock_levels survives as merchant intent.
const meaningful = (variants ?? []).filter((v) => !isPlaceholderDefaultVariant(v))
const payload: ProductCreateParams = {
@@ -123,7 +123,7 @@ function NewProductPage() {
v.preorderable === true ||
v.preorder_ships_at != null ||
v.backorder_limit != null ||
- (v.stock_items?.length ?? 0) > 0
+ (v.stock_levels?.length ?? 0) > 0
if (hasVariantOnlyData) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(payload as any).variants = [variantToWirePayload(v, 0)]
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 ceec398dad..bf5ccbbe02 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/stock-locations.tsx
@@ -1,6 +1,6 @@
import { zodResolver } from '@hookform/resolvers/zod'
import type {
- StockItem,
+ StockLevel,
StockLocation,
StockLocationCreateParams,
StockLocationUpdateParams,
@@ -50,7 +50,7 @@ import { useEffect, useMemo, useState } from 'react'
import { Controller, type UseFormReturn, useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { z } from 'zod/v4'
-import { useStockItems, useUpdateStockItem } from '../../../../hooks/use-stock-items'
+import { useStockLevels, useUpdateStockLevel } from '../../../../hooks/use-stock-levels'
import {
useCreateStockLocation,
useDeleteStockLocation,
@@ -291,7 +291,7 @@ function EditStockLocationSheet({
<form onSubmit={form.handleSubmit(onSubmit)} className="flex min-h-0 flex-1 flex-col">
<div className="flex flex-1 flex-col gap-4 overflow-y-auto p-4">
<StockLocationFormFields form={form} />
- <StockItemsPanel stockLocationId={id} />
+ <StockLevelsPanel stockLocationId={id} />
</div>
<SheetFooter>
<Button
@@ -322,11 +322,11 @@ function EditStockLocationSheet({
// Stock Items panel — adjust on-hand counts at this location
// ============================================================================
-function StockItemsPanel({ stockLocationId }: { stockLocationId: string }) {
+function StockLevelsPanel({ stockLocationId }: { stockLocationId: string }) {
const { t } = useTranslation()
const [search, setSearch] = useState('')
const [page, setPage] = useState(1)
- const { data, isFetching } = useStockItems({
+ const { data, isFetching } = useStockLevels({
stock_location_id_eq: stockLocationId,
variant_sku_or_variant_product_name_cont: search.length >= 2 ? search : undefined,
page,
@@ -338,7 +338,7 @@ function StockItemsPanel({ stockLocationId }: { stockLocationId: string }) {
// Group by product so multi-variant products read as one card with sub-rows
// instead of as N unrelated rows. Sort: low stock first, then product name.
const groups = useMemo(
- () => groupItemsByProduct(items, t('admin.stock_locations.stock_items.unknown_product')),
+ () => groupItemsByProduct(items, t('admin.stock_locations.stock_levels.unknown_product')),
[items, t],
)
@@ -346,13 +346,13 @@ function StockItemsPanel({ stockLocationId }: { stockLocationId: string }) {
<div className="rounded-md border">
<div className="flex items-center justify-between gap-2 border-b px-4 py-3">
<div>
- <h3 className="text-sm font-medium">{t('admin.stock_locations.stock_items.title')}</h3>
+ <h3 className="text-sm font-medium">{t('admin.stock_locations.stock_levels.title')}</h3>
<p className="text-xs text-muted-foreground">
- {t('admin.stock_locations.stock_items.help')}
+ {t('admin.stock_locations.stock_levels.help')}
</p>
</div>
<Input
- placeholder={t('admin.stock_locations.stock_items.search_placeholder')}
+ placeholder={t('admin.stock_locations.stock_levels.search_placeholder')}
value={search}
onChange={(e) => {
setSearch(e.target.value)
@@ -366,8 +366,8 @@ function StockItemsPanel({ stockLocationId }: { stockLocationId: string }) {
) : items.length === 0 ? (
<div className="px-4 py-6 text-sm text-muted-foreground">
{search
- ? t('admin.stock_locations.stock_items.empty_search')
- : t('admin.stock_locations.stock_items.empty')}
+ ? t('admin.stock_locations.stock_levels.empty_search')
+ : t('admin.stock_locations.stock_levels.empty')}
</div>
) : (
<div className="divide-y">
@@ -407,17 +407,17 @@ function StockItemsPanel({ stockLocationId }: { stockLocationId: string }) {
)
}
-interface StockItemGroup {
+interface StockLevelGroup {
productId: string
productName: string
- items: StockItem[]
+ items: StockLevel[]
hasLowStock: boolean
}
const LOW_STOCK_THRESHOLD = 5
-function groupItemsByProduct(items: StockItem[], unknownProductLabel: string): StockItemGroup[] {
- const map = new Map<string, StockItemGroup>()
+function groupItemsByProduct(items: StockLevel[], unknownProductLabel: string): StockLevelGroup[] {
+ const map = new Map<string, StockLevelGroup>()
for (const item of items) {
const productId = item.variant?.product_id ?? '__unknown__'
const productName = item.variant?.product_name ?? unknownProductLabel
@@ -439,7 +439,7 @@ function groupItemsByProduct(items: StockItem[], unknownProductLabel: string): S
return groups
}
-function ProductGroup({ group, defaultOpen }: { group: StockItemGroup; defaultOpen: boolean }) {
+function ProductGroup({ group, defaultOpen }: { group: StockLevelGroup; defaultOpen: boolean }) {
const { t } = useTranslation()
const [open, setOpen] = useState(defaultOpen)
@@ -454,8 +454,8 @@ function ProductGroup({ group, defaultOpen }: { group: StockItemGroup; defaultOp
<div className="min-w-0 flex-1">
<div className="truncate text-sm font-medium">{group.productName}</div>
<div className="truncate text-xs text-muted-foreground">
- {t('admin.stock_locations.stock_items.variant_count', { count: group.items.length })}
- {group.hasLowStock && ` · ${t('admin.stock_locations.stock_items.low_stock_marker')}`}
+ {t('admin.stock_locations.stock_levels.variant_count', { count: group.items.length })}
+ {group.hasLowStock && ` · ${t('admin.stock_locations.stock_levels.low_stock_marker')}`}
</div>
</div>
</CollapsibleTrigger>
@@ -464,20 +464,20 @@ function ProductGroup({ group, defaultOpen }: { group: StockItemGroup; defaultOp
<thead className="sticky top-0 bg-card text-xs text-muted-foreground">
<tr className="border-y">
<th className="px-4 py-2 text-left font-medium">
- {t('admin.stock_locations.stock_items.table.variant')}
+ {t('admin.stock_locations.stock_levels.table.variant')}
</th>
<th className="px-3 py-2 text-right font-medium">
- {t('admin.stock_locations.stock_items.table.on_hand')}
+ {t('admin.stock_locations.stock_levels.table.on_hand')}
</th>
<th className="px-3 py-2 text-left font-medium">
- {t('admin.stock_locations.stock_items.table.backorder')}
+ {t('admin.stock_locations.stock_levels.table.backorder')}
</th>
<th className="px-3 py-2" />
</tr>
</thead>
<tbody>
{group.items.map((item) => (
- <StockItemRow key={item.id} item={item} />
+ <StockLevelRow key={item.id} item={item} />
))}
</tbody>
</table>
@@ -486,10 +486,10 @@ function ProductGroup({ group, defaultOpen }: { group: StockItemGroup; defaultOp
)
}
-function StockItemRow({ item }: { item: StockItem }) {
+function StockLevelRow({ item }: { item: StockLevel }) {
const { t } = useTranslation()
const { storeId } = Route.useParams()
- const updateMutation = useUpdateStockItem(item.id)
+ const updateMutation = useUpdateStockLevel(item.id)
const [count, setCount] = useState<number>(item.count_on_hand)
const [backorderable, setBackorderable] = useState<boolean>(item.backorderable)
diff --git a/packages/dashboard/src/schemas/product.ts b/packages/dashboard/src/schemas/product.ts
index d70e8e7254..5017f87063 100644
--- a/packages/dashboard/src/schemas/product.ts
+++ b/packages/dashboard/src/schemas/product.ts
@@ -1,7 +1,7 @@
import { requiredMessage } from '@spree/dashboard-ui'
import { z } from 'zod/v4'
-export const stockItemFormSchema = z.object({
+export const stockLevelFormSchema = z.object({
id: z.string().optional(),
stock_location_id: z.string(),
stock_location_name: z.string().optional(),
@@ -9,7 +9,7 @@ export const stockItemFormSchema = z.object({
backorderable: z.boolean(),
})
-export type StockItemFormValues = z.infer<typeof stockItemFormSchema>
+export type StockLevelFormValues = z.infer<typeof stockLevelFormSchema>
export const variantOptionPairSchema = z.object({
name: z.string().min(1),
@@ -54,7 +54,7 @@ export const variantFormSchema = z.object({
backorder_limit: z.coerce.number().int().nonnegative().nullable().optional(),
tax_category_id: z.string().nullable().optional(),
prices: z.array(variantPriceFormSchema).optional(),
- stock_items: z.array(stockItemFormSchema).optional(),
+ stock_levels: z.array(stockLevelFormSchema).optional(),
})
export type VariantFormValues = z.infer<typeof variantFormSchema>
@@ -147,7 +147,7 @@ export const productFormSchema = z.object({
export type ProductFormValues = z.infer<typeof productFormSchema>
// Defaults for the "new product" page. Starts with a single placeholder
-// variant (no options, empty stock_items/prices) so the variants matrix
+// variant (no options, empty stock_levels/prices) so the variants matrix
// renders a "Default variant" row the merchant can edit pre-save. On submit
// the page strips this row if it carries no meaningful data, letting
// Spree::Product#variants= auto-create the default variant server-side.
@@ -180,7 +180,7 @@ export function newProductFormDefaults(): ProductFormValues {
track_inventory: true,
tax_category_id: null,
prices: [],
- stock_items: [],
+ stock_levels: [],
},
],
custom_fields: [],
@@ -205,7 +205,7 @@ export function isPlaceholderDefaultVariant(v: VariantFormValues): boolean {
!v.barcode &&
v.options.length === 0 &&
(v.prices ?? []).length === 0 &&
- (v.stock_items ?? []).length === 0 &&
+ (v.stock_levels ?? []).length === 0 &&
v.weight == null &&
v.height == null &&
v.width == null &&
diff --git a/packages/dashboard/src/schemas/webhook-endpoint.ts b/packages/dashboard/src/schemas/webhook-endpoint.ts
index 7973d949ed..a51287a5da 100644
--- a/packages/dashboard/src/schemas/webhook-endpoint.ts
+++ b/packages/dashboard/src/schemas/webhook-endpoint.ts
@@ -226,8 +226,8 @@ export const WEBHOOK_EVENT_GROUPS: readonly WebhookEventGroup[] = [
],
},
{
- labelKey: 'admin.pages.settings.webhooks.event_groups.stock_item',
- events: ['stock_item.created', 'stock_item.deleted', 'stock_item.updated'],
+ labelKey: 'admin.pages.settings.webhooks.event_groups.stock_level',
+ events: ['stock_level.created', 'stock_level.deleted', 'stock_level.updated'],
},
{
labelKey: 'admin.pages.settings.webhooks.event_groups.stock_movement',