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.4: Rename the admin stock items endpoint to stock levels

Łukasz Adamczyk531198b4fc68
diff --git a/packages/admin-sdk/src/types/generated/StockItem.ts b/packages/admin-sdk/src/types/generated/StockLevel.ts
similarity index 81%
rename from packages/admin-sdk/src/types/generated/StockItem.ts
rename to packages/admin-sdk/src/types/generated/StockLevel.ts
index f26d39bca5..70bb4cb312 100644
--- a/packages/admin-sdk/src/types/generated/StockItem.ts
+++ b/packages/admin-sdk/src/types/generated/StockLevel.ts
@@ -1,9 +1,9 @@
-// Typelizer digest 16c2fb7a45f1b9afef6032d5fd441d1c
+// Typelizer digest ed9c8e602f9172a2a75fb4611d9cb4e4
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {StockLocation, Variant} from '@/types'
-interface StockItem {
+interface StockLevel {
id: string;
count_on_hand: number;
backorderable: boolean;
@@ -18,4 +18,4 @@ interface StockItem {
variant?: Variant;
}
-export default StockItem;
+export default StockLevel;
diff --git a/packages/admin-sdk/src/types/generated/StockReservation.ts b/packages/admin-sdk/src/types/generated/StockReservation.ts
index 1faec8fd92..aeb56d143f 100644
--- a/packages/admin-sdk/src/types/generated/StockReservation.ts
+++ b/packages/admin-sdk/src/types/generated/StockReservation.ts
@@ -1,10 +1,10 @@
-// Typelizer digest 1e93f4cccfef1a17e1cf1c9a519c28ee
+// Typelizer digest cfd43df1761e538ec5bd714a5d0c5c59
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
interface StockReservation {
id: string;
- stock_item_id: string;
+ stock_level_id: string;
line_item_id: string;
order_id: string;
variant_id: string | null;
diff --git a/packages/admin-sdk/src/types/generated/Variant.ts b/packages/admin-sdk/src/types/generated/Variant.ts
index 93b5818954..f9058f42f0 100644
--- a/packages/admin-sdk/src/types/generated/Variant.ts
+++ b/packages/admin-sdk/src/types/generated/Variant.ts
@@ -1,7 +1,7 @@
// Typelizer digest 7cc8ed65c8fcb83f7ce9e199a1b59cf6
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
-import type {Price, PriceHistory, Media, OptionValue, CustomField, StockItem} from '@/types'
+import type {Price, PriceHistory, Media, OptionValue, CustomField, StockLevel} from '@/types'
interface Variant {
id: string;
@@ -48,7 +48,7 @@ interface Variant {
total_on_hand: number | null;
product_name: string;
prices?: Array<Price>;
- stock_items?: Array<StockItem>;
+ stock_levels?: Array<StockLevel>;
}
export default Variant;
diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.ts
index 9baeb43e3f..c385b9ef3c 100644
--- a/packages/admin-sdk/src/types/generated/index.ts
+++ b/packages/admin-sdk/src/types/generated/index.ts
@@ -78,7 +78,7 @@ export type { default as Return } from './Return'
export type { default as Role } from './Role'
export type { default as SetupTask } from './SetupTask'
export type { default as State } from './State'
-export type { default as StockItem } from './StockItem'
+export type { default as StockLevel } from './StockLevel'
export type { default as StockLocation } from './StockLocation'
export type { default as StockReservation } from './StockReservation'
export type { default as StockTransfer } from './StockTransfer'
diff --git a/packages/dashboard/src/hooks/use-stock-items.ts b/packages/dashboard/src/hooks/use-stock-levels.ts
similarity index 100%
rename from packages/dashboard/src/hooks/use-stock-items.ts
rename to packages/dashboard/src/hooks/use-stock-levels.ts
diff --git a/spree/api/app/controllers/concerns/spree/api/v3/admin/product_listing.rb b/spree/api/app/controllers/concerns/spree/api/v3/admin/product_listing.rb
index 91bc94ddf7..64ba1e260a 100644
--- a/spree/api/app/controllers/concerns/spree/api/v3/admin/product_listing.rb
+++ b/spree/api/app/controllers/concerns/spree/api/v3/admin/product_listing.rb
@@ -34,8 +34,8 @@ module Spree
:product_type,
{ product_publications: :channel },
{ primary_media: [attachment_attachment: :blob] },
- { default_variant: [:prices, { stock_items: [:stock_location, :active_stock_reservations] }] },
- { variants: [:prices, { stock_items: [:stock_location, :active_stock_reservations] }] }
+ { default_variant: [:prices, { stock_levels: [:stock_location, :active_stock_reservations] }] },
+ { variants: [:prices, { stock_levels: [:stock_location, :active_stock_reservations] }] }
]
end
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb
index c6e327da15..d1a0f2b431 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/prices_controller.rb
@@ -84,7 +84,7 @@ module Spree
:prices,
product: :tax_category,
option_values: :option_type,
- stock_items: [:stock_location, :active_stock_reservations]
+ stock_levels: [:stock_location, :active_stock_reservations]
]
}
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/products/variants_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/products/variants_controller.rb
index 4642bcd59f..175cb05873 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/products/variants_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/products/variants_controller.rb
@@ -26,7 +26,7 @@ module Spree
end
def scope_includes
- [:prices, stock_items: :stock_location]
+ [:prices, stock_levels: :stock_location]
end
def permitted_params
@@ -38,7 +38,7 @@ module Spree
:track_inventory, :preorderable, :preorder_ships_at, :backorder_limit, :tax_category_id, :position,
options: [:name, :value],
prices: [:amount, :compare_at_amount, :currency],
- stock_items: [:stock_location_id, :count_on_hand, :backorderable]
+ stock_levels: [:stock_location_id, :count_on_hand, :backorderable]
)
end
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb
index 2040337cea..c9f14a15a6 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/products_controller.rb
@@ -242,7 +242,7 @@ module Spree
:track_inventory, :preorderable, :preorder_ships_at, :backorder_limit, :tax_category_id, :position,
options: [:name, :value],
prices: [:amount, :compare_at_amount, :currency],
- stock_items: [:id, :stock_location_id, :count_on_hand, :backorderable]
+ stock_levels: [:id, :stock_location_id, :count_on_hand, :backorderable]
]
)
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/stock_items_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/stock_levels_controller.rb
similarity index 68%
rename from spree/api/app/controllers/spree/api/v3/admin/stock_items_controller.rb
rename to spree/api/app/controllers/spree/api/v3/admin/stock_levels_controller.rb
index af7f62226d..700be94b8c 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/stock_items_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/stock_levels_controller.rb
@@ -2,34 +2,34 @@ module Spree
module Api
module V3
module Admin
- # Stock items are auto-created when a variant lands at a stock
+ # Stock levels are auto-created when a variant lands at a stock
# location, so there's deliberately no `create` route — use the
# variants / stock-locations endpoints for that flow.
- class StockItemsController < ResourceController
+ class StockLevelsController < ResourceController
scoped_resource :stock
protected
def model_class
- Spree::StockItem
+ Spree::StockLevel
end
def serializer_class
- Spree.api.admin_stock_item_serializer
+ Spree.api.admin_stock_level_serializer
end
def collection_includes
[:stock_location, :variant]
end
- # `StockItem.for_store` already applies its own `distinct`, and
+ # `StockLevel.for_store` already applies its own `distinct`, and
# `id`-asc gives a stable order across edits (variant.position
# alone isn't unique — see git blame for the row-jumping bug).
def apply_collection_sort(collection)
- collection.order(Spree::StockItem.arel_table[:id].asc)
+ collection.order(Spree::StockLevel.arel_table[:id].asc)
end
- # Stock items are auto-created against a (variant, stock_location)
+ # Stock levels are auto-created against a (variant, stock_location)
# pair and never re-pointed, so update only touches the count and
# backorder flag — not the variant or location FKs.
def permitted_params
diff --git a/spree/api/app/controllers/spree/api/v3/admin/stock_reservations_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/stock_reservations_controller.rb
index 28af295a6d..9aa256be63 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/stock_reservations_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/stock_reservations_controller.rb
@@ -20,7 +20,7 @@ module Spree
end
def collection_includes
- [{ stock_item: [:variant, :stock_location], line_item: [], order: [] }]
+ [{ stock_level: [:variant, :stock_location], line_item: [], order: [] }]
end
end
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/variants_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/variants_controller.rb
index 53a573a2ea..8409ec5ee7 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/variants_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/variants_controller.rb
@@ -21,7 +21,7 @@ module Spree
def scope_includes
[
- :prices, stock_items: :stock_location,
+ :prices, stock_levels: :stock_location,
option_values: :option_type,
primary_media: [attachment_attachment: :blob]
]
diff --git a/spree/api/app/controllers/spree/api/v3/resource_controller.rb b/spree/api/app/controllers/spree/api/v3/resource_controller.rb
index 8fc2df897d..8697eab39d 100644
--- a/spree/api/app/controllers/spree/api/v3/resource_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/resource_controller.rb
@@ -315,7 +315,7 @@ module Spree
end
# Override in subclass to eager load associations that don't work well
- # with ar_lazy_preload (e.g., prices, stock_items)
+ # with ar_lazy_preload (e.g., prices, stock_levels)
def scope_includes
[]
end
diff --git a/spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb b/spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb
index 6901d2b81f..78212ae42e 100644
--- a/spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/delivery_methods_controller.rb
@@ -97,8 +97,8 @@ module Spree
next true if line_item.variant.product.digital?
next true unless line_item.variant.should_track_inventory?
- stock_item = location.stock_item(line_item.variant)
- stock_item.present? && stock_item.count_on_hand >= line_item.quantity
+ stock_level = location.stock_level(line_item.variant)
+ stock_level.present? && stock_level.count_on_hand >= line_item.quantity
end
end
end
diff --git a/spree/api/app/controllers/spree/api/v3/store/products_controller.rb b/spree/api/app/controllers/spree/api/v3/store/products_controller.rb
index 963b8b96a8..c3f54c4848 100644
--- a/spree/api/app/controllers/spree/api/v3/store/products_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/products_controller.rb
@@ -37,8 +37,8 @@ module Spree
[
product_publications: [],
primary_media: [attachment_attachment: :blob],
- default_variant: [:prices, stock_items: [:stock_location, :active_stock_reservations]],
- variants: [:prices, stock_items: [:stock_location, :active_stock_reservations]]
+ default_variant: [:prices, stock_levels: [:stock_location, :active_stock_reservations]],
+ variants: [:prices, stock_levels: [:stock_location, :active_stock_reservations]]
]
end
diff --git a/spree/api/app/serializers/spree/api/v3/admin/stock_item_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/stock_level_serializer.rb
similarity index 70%
rename from spree/api/app/serializers/spree/api/v3/admin/stock_item_serializer.rb
rename to spree/api/app/serializers/spree/api/v3/admin/stock_level_serializer.rb
index 7acc4e11b1..a1798d0c99 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/stock_item_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/stock_level_serializer.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V3
module Admin
- class StockItemSerializer < V3::StockItemSerializer
+ class StockLevelSerializer < V3::StockLevelSerializer
typelize metadata: 'Record<string, unknown>',
allocated_count: :number, available_count: :number
@@ -11,13 +11,13 @@ module Spree
# Units already allocated to pending shipments. Always 0 in 5.5;
# 6.0 Typed Stock Movements wires it up.
- attribute :allocated_count do |stock_item|
- stock_item.allocated_count.to_i
+ attribute :allocated_count do |stock_level|
+ stock_level.allocated_count.to_i
end
- # Physical stock minus allocated units (per stock_item).
- attribute :available_count do |stock_item|
- stock_item.available_count.to_i
+ # Physical stock minus allocated units (per stock_level).
+ attribute :available_count do |stock_level|
+ stock_level.available_count.to_i
end
one :stock_location,
diff --git a/spree/api/app/serializers/spree/api/v3/admin/stock_reservation_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/stock_reservation_serializer.rb
index a361b7de43..ed8cba35bc 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/stock_reservation_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/stock_reservation_serializer.rb
@@ -3,7 +3,7 @@ module Spree
module V3
module Admin
class StockReservationSerializer < V3::StockReservationSerializer
- typelize stock_item_id: :string,
+ typelize stock_level_id: :string,
line_item_id: :string,
order_id: :string,
variant_id: [:string, nullable: true],
@@ -12,8 +12,8 @@ module Spree
expires_at: :string,
active: :boolean
- attribute :stock_item_id do |reservation|
- reservation.stock_item.prefixed_id
+ attribute :stock_level_id do |reservation|
+ reservation.stock_level.prefixed_id
end
attribute :line_item_id do |reservation|
@@ -25,11 +25,11 @@ module Spree
end
attribute :variant_id do |reservation|
- reservation.stock_item&.variant&.prefixed_id
+ reservation.stock_level&.variant&.prefixed_id
end
attribute :stock_location_id do |reservation|
- reservation.stock_item&.stock_location&.prefixed_id
+ reservation.stock_level&.stock_location&.prefixed_id
end
attributes :quantity, expires_at: :iso8601
diff --git a/spree/api/app/serializers/spree/api/v3/admin/variant_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/variant_serializer.rb
index 279ddde058..eb7b81892d 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/variant_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/variant_serializer.rb
@@ -36,7 +36,7 @@ module Spree
end
# Physical pool minus already-allocated units. In 5.5 allocated_count
- # is always 0, so this equals SUM(stock_items.count_on_hand).
+ # is always 0, so this equals SUM(stock_levels.count_on_hand).
attribute :available_stock do |variant|
variant.available_stock.to_i if variant.should_track_inventory?
end
@@ -75,9 +75,9 @@ module Spree
resource: proc { Spree.api.admin_custom_field_serializer },
if: proc { expand?('custom_fields') }
- many :stock_items,
- resource: proc { Spree.api.admin_stock_item_serializer },
- if: proc { expand?('stock_items') }
+ many :stock_levels,
+ resource: proc { Spree.api.admin_stock_level_serializer },
+ if: proc { expand?('stock_levels') }
end
end
end
diff --git a/spree/api/app/serializers/spree/api/v3/stock_item_serializer.rb b/spree/api/app/serializers/spree/api/v3/stock_level_serializer.rb
similarity index 58%
rename from spree/api/app/serializers/spree/api/v3/stock_item_serializer.rb
rename to spree/api/app/serializers/spree/api/v3/stock_level_serializer.rb
index 30b1d9c201..50ad9bd492 100644
--- a/spree/api/app/serializers/spree/api/v3/stock_item_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/stock_level_serializer.rb
@@ -3,18 +3,18 @@
module Spree
module Api
module V3
- class StockItemSerializer < BaseSerializer
+ class StockLevelSerializer < BaseSerializer
typelize count_on_hand: :number, backorderable: :boolean,
stock_location_id: [:string, nullable: true], variant_id: [:string, nullable: true]
attributes :count_on_hand, :backorderable
- attribute :stock_location_id do |stock_item|
- stock_item.stock_location&.prefixed_id
+ attribute :stock_location_id do |stock_level|
+ stock_level.stock_location&.prefixed_id
end
- attribute :variant_id do |stock_item|
- stock_item.variant&.prefixed_id
+ attribute :variant_id do |stock_level|
+ stock_level.variant&.prefixed_id
end
end
end
diff --git a/spree/api/app/serializers/spree/api/v3/stock_movement_serializer.rb b/spree/api/app/serializers/spree/api/v3/stock_movement_serializer.rb
index 4a839edbdb..e901527cae 100644
--- a/spree/api/app/serializers/spree/api/v3/stock_movement_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/stock_movement_serializer.rb
@@ -6,7 +6,7 @@ module Spree
class StockMovementSerializer < BaseSerializer
typelize quantity: :number, action: [:string, nullable: true],
originator_type: [:string, nullable: true], originator_id: [:string, nullable: true],
- stock_item_id: [:string, nullable: true]
+ stock_level_id: [:string, nullable: true]
attributes :quantity, :action,
created_at: :iso8601, updated_at: :iso8601
@@ -20,8 +20,8 @@ module Spree
movement.originator&.prefixed_id
end
- attribute :stock_item_id do |movement|
- movement.stock_item&.prefixed_id
+ attribute :stock_level_id do |movement|
+ movement.stock_level&.prefixed_id
end
end
end
diff --git a/spree/api/config/initializers/typelizer.rb b/spree/api/config/initializers/typelizer.rb
index 2cf537cff1..3de913f8b8 100644
--- a/spree/api/config/initializers/typelizer.rb
+++ b/spree/api/config/initializers/typelizer.rb
@@ -23,7 +23,7 @@ Rails.application.config.after_initialize do
# Serializers that exist only for Admin API or events — no Store API controller
store_excluded = %w[
Asset CartPromotion OrderPromotion
- StockItem StockMovement StockTransfer
+ StockLevel StockMovement StockTransfer
Report Export Import ImportRow
TaxCategory Exchange ExchangeLineItem
Company
diff --git a/spree/api/config/routes.rb b/spree/api/config/routes.rb
index f925357728..2faebf1986 100644
--- a/spree/api/config/routes.rb
+++ b/spree/api/config/routes.rb
@@ -340,7 +340,7 @@ Spree::Core::Engine.add_routes do
# Inventory
resources :stock_locations
resources :stock_reservations, only: [:index, :show]
- resources :stock_items, only: [:index, :show, :update, :destroy]
+ resources :stock_levels, only: [:index, :show, :update, :destroy]
resources :stock_transfers, only: [:index, :show, :create, :destroy]
# Payment Methods
diff --git a/spree/api/lib/spree/api/dependencies.rb b/spree/api/lib/spree/api/dependencies.rb
index dcc1b4268e..cbcd1b6e6a 100644
--- a/spree/api/lib/spree/api/dependencies.rb
+++ b/spree/api/lib/spree/api/dependencies.rb
@@ -87,7 +87,7 @@ module Spree
promotion_serializer: 'Spree::Api::V3::PromotionSerializer',
refund_serializer: 'Spree::Api::V3::RefundSerializer',
report_serializer: 'Spree::Api::V3::ReportSerializer',
- stock_item_serializer: 'Spree::Api::V3::StockItemSerializer',
+ stock_level_serializer: 'Spree::Api::V3::StockLevelSerializer',
stock_movement_serializer: 'Spree::Api::V3::StockMovementSerializer',
stock_reservation_serializer: 'Spree::Api::V3::StockReservationSerializer',
stock_transfer_serializer: 'Spree::Api::V3::StockTransferSerializer',
@@ -124,7 +124,7 @@ module Spree
admin_option_type_serializer: 'Spree::Api::V3::Admin::OptionTypeSerializer',
admin_option_value_serializer: 'Spree::Api::V3::Admin::OptionValueSerializer',
admin_media_serializer: 'Spree::Api::V3::Admin::MediaSerializer',
- admin_stock_item_serializer: 'Spree::Api::V3::Admin::StockItemSerializer',
+ admin_stock_level_serializer: 'Spree::Api::V3::Admin::StockLevelSerializer',
admin_stock_transfer_serializer: 'Spree::Api::V3::Admin::StockTransferSerializer',
admin_shipment_serializer: 'Spree::Api::V3::Admin::FulfillmentSerializer',
admin_fulfillment_serializer: 'Spree::Api::V3::Admin::FulfillmentSerializer',
@@ -196,6 +196,33 @@ module Spree
}
include Spree::DependenciesHelper
+
+ # Pre-6.0 names for the StockItem → StockLevel serializers. Unlike the
+ # legacy workflow keys in core, these forward instead of stashing: a
+ # serializer renders the same model under a new class name, so an
+ # override written against the old key is still the class the host app
+ # wants used. Removed in 6.1.
+ LEGACY_SERIALIZER_KEYS = {
+ stock_item_serializer: :stock_level_serializer,
+ admin_stock_item_serializer: :admin_stock_level_serializer
+ }.freeze
+
+ LEGACY_SERIALIZER_KEYS.each do |legacy, current|
+ define_method("#{legacy}=") do |value|
+ Spree::Deprecation.warn("Spree.api.#{legacy}= is deprecated and will be removed in Spree 6.1. Use #{current}= instead.")
+ send("#{current}=", value)
+ end
+
+ define_method(legacy) do
+ Spree::Deprecation.warn("Spree.api.#{legacy} is deprecated and will be removed in Spree 6.1. Use #{current} instead.")
+ send(current)
+ end
+
+ define_method("#{legacy}_class") do
+ Spree::Deprecation.warn("Spree.api.#{legacy}_class is deprecated and will be removed in Spree 6.1. Use #{current}_class instead.")
+ send("#{current}_class")
+ end
+ end
end
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders/claims_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders/claims_controller_spec.rb
index 3a36788fc9..a5f826c5d4 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/orders/claims_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders/claims_controller_spec.rb
@@ -98,7 +98,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ClaimsController, type: :controlle
it 'sends a replacement for the lines chosen at resolve time' do
line = claim.claim_line_items.first
line.update!(send_replacement: false)
- line.variant.stock_items.first&.set_count_on_hand(10)
+ line.variant.stock_levels.first&.set_count_on_hand(10)
patch :resolve, params: {
order_id: order.prefixed_id,
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb
index d373fc79bc..2f31ef0caa 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb
@@ -400,7 +400,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::FulfillmentsController, type: :con
it 'splits items to a new fulfillment at a different stock location' do
variant = shipment.inventory_units.first.variant
target_stock_location = create(:stock_location, name: 'Warehouse 2')
- target_stock_location.stock_items.find_or_create_by(variant: variant).set_count_on_hand(10)
+ target_stock_location.stock_levels.find_or_create_by(variant: variant).set_count_on_hand(10)
patch :split, params: {
order_id: order.prefixed_id,
diff --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.rb
index 35fcd1a048..9ab602af25 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
@@ -338,8 +338,8 @@ RSpec.describe Spree::Api::V3::Admin::OrdersController, type: :controller do
let(:variant) { create(:variant) }
before do
- default_location.stock_item_or_create(variant).update!(count_on_hand: 10)
- preferred_location.stock_item_or_create(variant).update!(count_on_hand: 10)
+ default_location.stock_level_or_create(variant).update!(count_on_hand: 10)
+ preferred_location.stock_level_or_create(variant).update!(count_on_hand: 10)
end
let(:create_params) do
@@ -380,7 +380,7 @@ RSpec.describe Spree::Api::V3::Admin::OrdersController, type: :controller do
context 'when the preferred location does not stock the variant' do
before do
- preferred_location.stock_items.where(variant_id: variant.id).destroy_all
+ preferred_location.stock_levels.where(variant_id: variant.id).destroy_all
end
it 'falls back to the default location instead of erroring' do
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/products/variants_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products/variants_controller_spec.rb
index 3a523692f4..a60421873d 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/products/variants_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/products/variants_controller_spec.rb
@@ -61,7 +61,7 @@ RSpec.describe Spree::Api::V3::Admin::Products::VariantsController, type: :contr
expect(json_response['sku']).to eq('NEW-SKU-001')
end
- context 'with nested prices and stock_items' do
+ context 'with nested prices and stock_levels' do
let!(:stock_location_1) { Spree::StockLocation.first || create(:stock_location) }
let!(:stock_location_2) { create(:stock_location, name: 'Warehouse 2') }
@@ -75,7 +75,7 @@ RSpec.describe Spree::Api::V3::Admin::Products::VariantsController, type: :contr
{ currency: 'USD', amount: 19.99, compare_at_amount: 24.99 },
{ currency: 'EUR', amount: 17.99 }
],
- stock_items: [
+ stock_levels: [
{ stock_location_id: stock_location_1.prefixed_id, count_on_hand: 50, backorderable: false },
{ stock_location_id: stock_location_2.prefixed_id, count_on_hand: 10, backorderable: true }
]
@@ -90,11 +90,11 @@ RSpec.describe Spree::Api::V3::Admin::Products::VariantsController, type: :contr
expect(created_variant.prices.find_by(currency: 'USD').compare_at_amount.to_f).to eq(24.99)
expect(created_variant.prices.find_by(currency: 'EUR').amount.to_f).to eq(17.99)
- si_1 = created_variant.stock_items.find_by(stock_location: stock_location_1)
+ si_1 = created_variant.stock_levels.find_by(stock_location: stock_location_1)
expect(si_1.count_on_hand).to eq(50)
expect(si_1.backorderable).to eq(false)
- si_2 = created_variant.stock_items.find_by(stock_location: stock_location_2)
+ si_2 = created_variant.stock_levels.find_by(stock_location: stock_location_2)
expect(si_2.count_on_hand).to eq(10)
expect(si_2.backorderable).to eq(true)
end
@@ -161,20 +161,20 @@ RSpec.describe Spree::Api::V3::Admin::Products::VariantsController, type: :contr
end
end
- context 'with nested stock_items' do
+ context 'with nested stock_levels' do
let!(:stock_location) { Spree::StockLocation.first || create(:stock_location) }
it 'updates stock levels' do
patch :update, params: {
product_id: product.prefixed_id,
id: variant.prefixed_id,
- stock_items: [
+ stock_levels: [
{ stock_location_id: stock_location.prefixed_id, count_on_hand: 99 }
]
}, as: :json
expect(response).to have_http_status(:ok)
- expect(variant.reload.stock_items.find_by(stock_location: stock_location).count_on_hand).to eq(99)
+ expect(variant.reload.stock_levels.find_by(stock_location: stock_location).count_on_hand).to eq(99)
end
end
end
diff --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.rb
index bb7fd62349..05c6ea27f8 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
@@ -598,7 +598,7 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
# Mirrors the exact wire shape the dashboard ships from
# `new.tsx` for a simple product with media + inventory:
# - status, channels, custom_fields, media, variants[] with empty
- # options + stock_items routed to the default variant via apply_variants.
+ # options + stock_levels routed to the default variant via apply_variants.
blob1 = ActiveStorage::Blob.create_and_upload!(
io: File.open(Spree::Core::Engine.root.join('spec', 'fixtures', 'thinking-cat.jpg')),
filename: 'one.jpg',
@@ -622,7 +622,7 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
variants: [
{
position: 1, options: [], sku: '', weight: 0, track_inventory: true,
- stock_items: [
+ stock_levels: [
{ stock_location_id: location.prefixed_id, count_on_hand: 10, backorderable: false }
]
}
@@ -634,7 +634,7 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
expect(response).to have_http_status(:created)
created = Spree::Product.find_by(name: 'test product')
expect(created.media.count).to eq(2)
- expect(created.default_variant.stock_items.find_by(stock_location: location).count_on_hand).to eq(10)
+ expect(created.default_variant.stock_levels.find_by(stock_location: location).count_on_hand).to eq(10)
# Simple product has exactly one variant — the default variant.
expect(created.variants.count).to eq(1)
end
@@ -1061,12 +1061,12 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
end
end
- context 'with nested stock_items updates' do
+ context 'with nested stock_levels updates' do
let!(:stock_location) { Spree::StockLocation.first || create(:stock_location) }
let!(:variant_to_update) { create(:variant, product: product) }
- let!(:stock_item) do
- variant_to_update.stock_items.find_by(stock_location: stock_location) ||
- create(:stock_item, variant: variant_to_update, stock_location: stock_location, count_on_hand: 5, backorderable: false)
+ let!(:stock_level) do
+ variant_to_update.stock_levels.find_by(stock_location: stock_location) ||
+ create(:stock_level, variant: variant_to_update, stock_location: stock_location, count_on_hand: 5, backorderable: false)
end
it 'updates count_on_hand and backorderable per location' do
@@ -1075,7 +1075,7 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
variants: [
{
id: variant_to_update.prefixed_id,
- stock_items: [
+ stock_levels: [
{
stock_location_id: stock_location.prefixed_id,
count_on_hand: 42,
@@ -1087,9 +1087,9 @@ RSpec.describe Spree::Api::V3::Admin::ProductsController, type: :controller do
}, as: :json
expect(response).to have_http_status(:ok)
- stock_item.reload
- expect(stock_item.count_on_hand).to eq(42)
- expect(stock_item.backorderable).to be true
+ stock_level.reload
+ expect(stock_level.count_on_hand).to eq(42)
+ expect(stock_level.backorderable).to be true
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/stock_items_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/stock_levels_controller_spec.rb
similarity index 60%
rename from spree/api/spec/controllers/spree/api/v3/admin/stock_items_controller_spec.rb
rename to spree/api/spec/controllers/spree/api/v3/admin/stock_levels_controller_spec.rb
index f5d58b5217..4f3f22622e 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/stock_items_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/stock_levels_controller_spec.rb
@@ -1,13 +1,13 @@
require 'spec_helper'
-RSpec.describe Spree::Api::V3::Admin::StockItemsController, type: :controller do
+RSpec.describe Spree::Api::V3::Admin::StockLevelsController, type: :controller do
render_views
include_context 'API v3 Admin authenticated'
let!(:stock_location) { Spree::StockLocation.first || create(:stock_location) }
let!(:variant) { create(:variant) }
- let!(:stock_item) { variant.stock_items.find_by(stock_location: stock_location) || create(:stock_item, variant: variant, stock_location: stock_location) }
+ let!(:stock_level) { variant.stock_levels.find_by(stock_location: stock_location) || create(:stock_level, variant: variant, stock_location: stock_location) }
before { request.headers.merge!(headers) }
@@ -16,34 +16,34 @@ RSpec.describe Spree::Api::V3::Admin::StockItemsController, type: :controller do
get :index, as: :json
expect(response).to have_http_status(:ok)
- expect(json_response['data'].map { |s| s['id'] }).to include(stock_item.prefixed_id)
+ expect(json_response['data'].map { |s| s['id'] }).to include(stock_level.prefixed_id)
end
it 'filters by stock_location_id' do
other_location = create(:stock_location)
- _other_item = create(:stock_item, stock_location: other_location)
+ _other_item = create(:stock_level, stock_location: other_location)
get :index, params: { q: { stock_location_id_eq: stock_location.id } }, as: :json
expect(response).to have_http_status(:ok)
ids = json_response['data'].map { |s| s['id'] }
- expect(ids).to include(stock_item.prefixed_id)
+ expect(ids).to include(stock_level.prefixed_id)
end
end
describe 'PATCH #update' do
it 'updates count_on_hand' do
- patch :update, params: { id: stock_item.prefixed_id, count_on_hand: 42 }, as: :json
+ patch :update, params: { id: stock_level.prefixed_id, count_on_hand: 42 }, as: :json
expect(response).to have_http_status(:ok)
- expect(stock_item.reload.count_on_hand).to eq(42)
+ expect(stock_level.reload.count_on_hand).to eq(42)
end
it 'toggles backorderable' do
- patch :update, params: { id: stock_item.prefixed_id, backorderable: true }, as: :json
+ patch :update, params: { id: stock_level.prefixed_id, backorderable: true }, as: :json
expect(response).to have_http_status(:ok)
- expect(stock_item.reload.backorderable).to be true
+ expect(stock_level.reload.backorderable).to be true
end
it 'ignores variant_id and stock_location_id' do
@@ -51,25 +51,25 @@ RSpec.describe Spree::Api::V3::Admin::StockItemsController, type: :controller do
other_location = create(:stock_location)
patch :update, params: {
- id: stock_item.prefixed_id,
+ id: stock_level.prefixed_id,
variant_id: other_variant.prefixed_id,
stock_location_id: other_location.prefixed_id,
count_on_hand: 7
}, as: :json
expect(response).to have_http_status(:ok)
- expect(stock_item.reload.variant_id).to eq(variant.id)
- expect(stock_item.stock_location_id).to eq(stock_location.id)
- expect(stock_item.count_on_hand).to eq(7)
+ expect(stock_level.reload.variant_id).to eq(variant.id)
+ expect(stock_level.stock_location_id).to eq(stock_location.id)
+ expect(stock_level.count_on_hand).to eq(7)
end
end
describe 'DELETE #destroy' do
it 'destroys the stock item' do
- target = create(:stock_item, stock_location: create(:stock_location))
+ target = create(:stock_level, stock_location: create(:stock_location))
expect { delete :destroy, params: { id: target.prefixed_id }, as: :json }.
- to change(Spree::StockItem, :count).by(-1)
+ to change(Spree::StockLevel, :count).by(-1)
expect(response).to have_http_status(:no_content)
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/stock_reservations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/stock_reservations_controller_spec.rb
index 97fd05a531..f56e508e56 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/stock_reservations_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/stock_reservations_controller_spec.rb
@@ -27,11 +27,11 @@ RSpec.describe Spree::Api::V3::Admin::StockReservationsController, type: :contro
it 'serializes reservation with prefixed associations and active flag' do
subject
record = json_response['data'].find { |r| r['id'] == reservation.prefixed_id }
- expect(record['stock_item_id']).to eq(reservation.stock_item.prefixed_id)
+ expect(record['stock_level_id']).to eq(reservation.stock_level.prefixed_id)
expect(record['line_item_id']).to eq(reservation.line_item.prefixed_id)
expect(record['order_id']).to eq(reservation.order.prefixed_id)
- expect(record['variant_id']).to eq(reservation.stock_item.variant.prefixed_id)
- expect(record['stock_location_id']).to eq(reservation.stock_item.stock_location.prefixed_id)
+ expect(record['variant_id']).to eq(reservation.stock_level.variant.prefixed_id)
+ expect(record['stock_location_id']).to eq(reservation.stock_level.stock_location.prefixed_id)
expect(record['quantity']).to eq(reservation.quantity)
expect(record['active']).to be(true)
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/stock_transfers_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/stock_transfers_controller_spec.rb
index 713703b49f..58abf06bc4 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/stock_transfers_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/stock_transfers_controller_spec.rb
@@ -11,8 +11,8 @@ RSpec.describe Spree::Api::V3::Admin::StockTransfersController, type: :controlle
before do
request.headers.merge!(headers)
- source_location.stock_item_or_create(variant).update!(count_on_hand: 50)
- destination_location.stock_item_or_create(variant)
+ source_location.stock_level_or_create(variant).update!(count_on_hand: 50)
+ destination_location.stock_level_or_create(variant)
end
describe 'GET #index' do
@@ -42,15 +42,15 @@ RSpec.describe Spree::Api::V3::Admin::StockTransfersController, type: :controlle
to change(Spree::StockTransfer, :count).by(1)
expect(response).to have_http_status(:created)
- expect(source_location.stock_item(variant).reload.count_on_hand).to eq(45)
- expect(destination_location.stock_item(variant).reload.count_on_hand).to eq(5)
+ expect(source_location.stock_level(variant).reload.count_on_hand).to eq(45)
+ expect(destination_location.stock_level(variant).reload.count_on_hand).to eq(5)
end
it 'receives from external vendor when source is omitted' do
post :create, params: base_params.except(:source_location_id), as: :json
expect(response).to have_http_status(:created)
- expect(destination_location.stock_item(variant).reload.count_on_hand).to eq(5)
+ expect(destination_location.stock_level(variant).reload.count_on_hand).to eq(5)
end
it 'returns 422 when variants is empty' do
diff --git a/spree/api/spec/controllers/spree/api/v3/store/carts_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/carts_controller_spec.rb
index 6cb5fc5005..c4c945861c 100644
--- a/spree/api/spec/controllers/spree/api/v3/store/carts_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/store/carts_controller_spec.rb
@@ -242,7 +242,7 @@ RSpec.describe Spree::Api::V3::Store::CartsController, type: :controller do
before do
[variant, variant2].each do |v|
- v.stock_items.first.update!(count_on_hand: 10)
+ v.stock_levels.first.update!(count_on_hand: 10)
end
end
@@ -471,7 +471,7 @@ RSpec.describe Spree::Api::V3::Store::CartsController, type: :controller do
end
it 'returns warnings when a line item is out of stock' do
- cart.line_items.first.variant.stock_items.update_all(count_on_hand: 0, backorderable: false)
+ cart.line_items.first.variant.stock_levels.update_all(count_on_hand: 0, backorderable: false)
get :show, params: { id: cart.prefixed_id }
@@ -497,7 +497,7 @@ RSpec.describe Spree::Api::V3::Store::CartsController, type: :controller do
end
it 'removes the line item when returning a warning' do
- cart.line_items.first.variant.stock_items.update_all(count_on_hand: 0, backorderable: false)
+ cart.line_items.first.variant.stock_levels.update_all(count_on_hand: 0, backorderable: false)
original_item_count = cart.line_items.count
get :show, params: { id: cart.prefixed_id }
@@ -744,8 +744,8 @@ RSpec.describe Spree::Api::V3::Store::CartsController, type: :controller do
end
before do
- order.line_items.first.variant.stock_items.first.update!(backorderable: false)
- order.line_items.first.variant.stock_items.first.set_count_on_hand(20)
+ order.line_items.first.variant.stock_levels.first.update!(backorderable: false)
+ order.line_items.first.variant.stock_levels.first.set_count_on_hand(20)
end
it 'creates a reservation when the cart leaves the cart state' do
@@ -924,11 +924,11 @@ RSpec.describe Spree::Api::V3::Store::CartsController, type: :controller do
it 'removes any stock reservations belonging to the cart' do
line_item = cart.line_items.first
- line_item.variant.stock_items.first.update!(backorderable: false)
- line_item.variant.stock_items.first.set_count_on_hand(20)
+ line_item.variant.stock_levels.first.update!(backorderable: false)
+ line_item.variant.stock_levels.first.set_count_on_hand(20)
create(
:stock_reservation,
- stock_item: line_item.variant.stock_items.first,
+ stock_level: line_item.variant.stock_levels.first,
line_item: line_item,
cart: cart,
order: nil,
@@ -983,11 +983,11 @@ RSpec.describe Spree::Api::V3::Store::CartsController, type: :controller do
it 'releases stock reservations on successful completion' do
create(:payment, cart: order, amount: order.reload.total)
line_item = order.line_items.first
- line_item.variant.stock_items.first.update!(backorderable: false)
- line_item.variant.stock_items.first.set_count_on_hand(20)
+ line_item.variant.stock_levels.first.update!(backorderable: false)
+ line_item.variant.stock_levels.first.set_count_on_hand(20)
create(
:stock_reservation,
- stock_item: line_item.variant.stock_items.first,
+ stock_level: line_item.variant.stock_levels.first,
line_item: line_item,
cart: order,
order: nil,
diff --git a/spree/api/spec/controllers/spree/api/v3/store/delivery_methods_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/delivery_methods_controller_spec.rb
index e8762d461e..adcbfb2e2c 100644
--- a/spree/api/spec/controllers/spree/api/v3/store/delivery_methods_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/store/delivery_methods_controller_spec.rb
@@ -77,7 +77,7 @@ RSpec.describe Spree::Api::V3::Store::DeliveryMethodsController, type: :controll
it 'keeps the location even without local stock' do
pickup_location.update!(pickup_stock_policy: 'any')
- pickup_location.stock_item_or_create(cart.line_items.first.variant).set_count_on_hand(0)
+ pickup_location.stock_level_or_create(cart.line_items.first.variant).set_count_on_hand(0)
get :pickup_locations, params: { id: pickup_method.prefixed_id, cart_id: cart.prefixed_id }, as: :json
@@ -93,7 +93,7 @@ RSpec.describe Spree::Api::V3::Store::DeliveryMethodsController, type: :controll
end
it 'keeps locations that can fulfill the whole cart from local stock' do
- pickup_location.stock_item_or_create(variant).set_count_on_hand(10)
+ pickup_location.stock_level_or_create(variant).set_count_on_hand(10)
get :pickup_locations, params: { id: pickup_method.prefixed_id, cart_id: cart.prefixed_id }, as: :json
@@ -101,7 +101,7 @@ RSpec.describe Spree::Api::V3::Store::DeliveryMethodsController, type: :controll
end
it 'drops locations without local stock for the cart' do
- pickup_location.stock_item_or_create(variant).set_count_on_hand(0)
+ pickup_location.stock_level_or_create(variant).set_count_on_hand(0)
get :pickup_locations, params: { id: pickup_method.prefixed_id, cart_id: cart.prefixed_id }, as: :json
@@ -109,7 +109,7 @@ RSpec.describe Spree::Api::V3::Store::DeliveryMethodsController, type: :controll
end
it 'ignores items the counter will never hand over (mixed cart with a tracked digital item)' do
- pickup_location.stock_item_or_create(variant).set_count_on_hand(10)
+ pickup_location.stock_level_or_create(variant).set_count_on_hand(10)
digital_product = create(:digital_product, store: store)
digital_product.default_variant.update!(track_inventory: true)
diff --git a/spree/api/spec/integration/spree/api/v3/admin/orders/fulfillments_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/orders/fulfillments_spec.rb
index 4fb163e930..7841536e57 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/orders/fulfillments_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/orders/fulfillments_spec.rb
@@ -448,7 +448,7 @@ RSpec.describe 'Admin Order Fulfillments API', type: :request, swagger_doc: 'api
let(:body) { { variant_id: variant.prefixed_id, quantity: 1, stock_location_id: stock_location.prefixed_id } }
before do
- stock_location.stock_items.find_or_create_by(variant: variant).set_count_on_hand(10)
+ stock_location.stock_levels.find_or_create_by(variant: variant).set_count_on_hand(10)
end
run_test! do |response|
diff --git a/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb
index d9c3e604fb..5b6ed40a1a 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/products_spec.rb
@@ -99,7 +99,7 @@ RSpec.describe 'Admin Products API', type: :request, swagger_doc: 'api-reference
},
variants: {
type: :array,
- description: 'Array of variant payloads. Variants can declare multiple option pairs via `options:` and per-currency prices via `prices:`. Stock counts go in `stock_items:` (per stock location).',
+ description: 'Array of variant payloads. Variants can declare multiple option pairs via `options:` and per-currency prices via `prices:`. Stock counts go in `stock_levels:` (per stock location).',
items: {
type: :object,
properties: {
@@ -129,7 +129,7 @@ RSpec.describe 'Admin Products API', type: :request, swagger_doc: 'api-reference
}
}
},
- stock_items: {
+ stock_levels: {
type: :array,
description: 'Per-stock-location inventory. Upserted by stock_location_id.',
items: {
@@ -252,7 +252,7 @@ RSpec.describe 'Admin Products API', type: :request, swagger_doc: 'api-reference
},
variants: {
type: :array,
- description: 'Array of variant payloads. Variants can declare multiple option pairs via `options:` and per-currency prices via `prices:`. Stock counts go in `stock_items:` (per stock location).',
+ description: 'Array of variant payloads. Variants can declare multiple option pairs via `options:` and per-currency prices via `prices:`. Stock counts go in `stock_levels:` (per stock location).',
items: {
type: :object,
properties: {
@@ -282,7 +282,7 @@ RSpec.describe 'Admin Products API', type: :request, swagger_doc: 'api-reference
}
}
},
- stock_items: {
+ stock_levels: {
type: :array,
description: 'Per-stock-location inventory. Upserted by stock_location_id.',
items: {
diff --git a/spree/api/spec/integration/spree/api/v3/admin/variants_spec.rb b/spree/api/spec/integration/spree/api/v3/admin/variants_spec.rb
index c24010aa48..4cae054b40 100644
--- a/spree/api/spec/integration/spree/api/v3/admin/variants_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/admin/variants_spec.rb
@@ -26,7 +26,7 @@ RSpec.describe 'Admin Variants API', type: :request, swagger_doc: 'api-reference
parameter name: :page, in: :query, type: :integer, required: false, description: 'Page number'
parameter name: :limit, in: :query, type: :integer, required: false, description: 'Number of records per page'
parameter name: :expand, in: :query, type: :string, required: false,
- description: 'Comma-separated associations to expand (e.g., images, prices, stock_items, option_values). Use dot notation for nested expand (max 4 levels).'
+ description: 'Comma-separated associations to expand (e.g., images, prices, stock_levels, option_values). Use dot notation for nested expand (max 4 levels).'
parameter name: :fields, in: :query, type: :string, required: false,
description: 'Comma-separated list of fields to include (e.g., sku,price,stock). id is always included.'
@@ -101,7 +101,7 @@ RSpec.describe 'Admin Variants API', type: :request, swagger_doc: 'api-reference
}
}
},
- stock_items: {
+ stock_levels: {
type: :array,
description: 'Per-stock-location inventory. Upserted by stock_location_id.',
items: {
@@ -157,7 +157,7 @@ RSpec.describe 'Admin Variants API', type: :request, swagger_doc: 'api-reference
parameter name: :product_id, in: :path, type: :string, required: true, description: 'Product ID'
parameter name: :id, in: :path, type: :string, required: true, description: 'Variant ID'
parameter name: :expand, in: :query, type: :string, required: false,
- description: 'Comma-separated associations to expand (e.g., images, prices, stock_items, option_values). Use dot notation for nested expand (max 4 levels).'
+ description: 'Comma-separated associations to expand (e.g., images, prices, stock_levels, option_values). Use dot notation for nested expand (max 4 levels).'
parameter name: :fields, in: :query, type: :string, required: false,
description: 'Comma-separated list of fields to include (e.g., sku,price,stock). id is always included.'
@@ -239,7 +239,7 @@ RSpec.describe 'Admin Variants API', type: :request, swagger_doc: 'api-reference
}
}
},
- stock_items: {
+ stock_levels: {
type: :array,
description: 'Per-stock-location inventory. Upserted by stock_location_id.',
items: {
diff --git a/spree/api/spec/integration/spree/api/v3/store/carts_spec.rb b/spree/api/spec/integration/spree/api/v3/store/carts_spec.rb
index 6d854f0058..fd09e5f97d 100644
--- a/spree/api/spec/integration/spree/api/v3/store/carts_spec.rb
+++ b/spree/api/spec/integration/spree/api/v3/store/carts_spec.rb
@@ -155,7 +155,7 @@ RSpec.describe 'Carts API', type: :request, swagger_doc: 'api-reference/store.ya
let(:id) { cart.prefixed_id }
before do
- cart.products.first.stock_items.update_all(count_on_hand: 0, backorderable: false)
+ cart.products.first.stock_levels.update_all(count_on_hand: 0, backorderable: false)
end
run_test! do |response|
diff --git a/spree/api/spec/serializers/spree/api/v3/stock_item_serializer_spec.rb b/spree/api/spec/serializers/spree/api/v3/stock_level_serializer_spec.rb
similarity index 58%
rename from spree/api/spec/serializers/spree/api/v3/stock_item_serializer_spec.rb
rename to spree/api/spec/serializers/spree/api/v3/stock_level_serializer_spec.rb
index 5144fe3bc5..806978eb7e 100644
--- a/spree/api/spec/serializers/spree/api/v3/stock_item_serializer_spec.rb
+++ b/spree/api/spec/serializers/spree/api/v3/stock_level_serializer_spec.rb
@@ -2,12 +2,12 @@
require 'spec_helper'
-RSpec.describe Spree::Api::V3::StockItemSerializer do
+RSpec.describe Spree::Api::V3::StockLevelSerializer do
let(:store) { @default_store }
- let(:stock_item) { create(:stock_item) }
+ let(:stock_level) { create(:stock_level) }
let(:base_params) { { store: store, currency: 'USD' } }
- subject { described_class.new(stock_item, params: base_params).to_h }
+ subject { described_class.new(stock_level, params: base_params).to_h }
it 'includes all expected attributes' do
expect(subject.keys).to match_array(%w[
@@ -16,15 +16,15 @@ RSpec.describe Spree::Api::V3::StockItemSerializer do
end
it 'returns the prefixed id' do
- expect(subject['id']).to eq(stock_item.prefixed_id)
+ expect(subject['id']).to eq(stock_level.prefixed_id)
end
it 'returns prefixed stock_location_id' do
- expect(subject['stock_location_id']).to eq(stock_item.stock_location.prefixed_id)
+ expect(subject['stock_location_id']).to eq(stock_level.stock_location.prefixed_id)
end
it 'returns prefixed variant_id' do
- expect(subject['variant_id']).to eq(stock_item.variant.prefixed_id)
+ expect(subject['variant_id']).to eq(stock_level.variant.prefixed_id)
end
it 'returns count_on_hand as number' do
diff --git a/spree/api/spec/serializers/spree/api/v3/stock_movement_serializer_spec.rb b/spree/api/spec/serializers/spree/api/v3/stock_movement_serializer_spec.rb
index 276faf5e31..f29c8aefe6 100644
--- a/spree/api/spec/serializers/spree/api/v3/stock_movement_serializer_spec.rb
+++ b/spree/api/spec/serializers/spree/api/v3/stock_movement_serializer_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe Spree::Api::V3::StockMovementSerializer do
it 'includes all expected attributes' do
expect(subject.keys).to match_array(%w[
- id quantity action originator_type originator_id stock_item_id created_at updated_at
+ id quantity action originator_type originator_id stock_level_id created_at updated_at
])
end
@@ -19,7 +19,7 @@ RSpec.describe Spree::Api::V3::StockMovementSerializer do
expect(subject['id']).to eq(stock_movement.prefixed_id)
end
- it 'returns prefixed stock_item_id' do
- expect(subject['stock_item_id']).to eq(stock_movement.stock_item.prefixed_id)
+ it 'returns prefixed stock_level_id' do
+ expect(subject['stock_level_id']).to eq(stock_movement.stock_level.prefixed_id)
end
end