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.

added soft delete to `StockLocation` (#12062)

Damian Legawiec42684add0adf
diff --git a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb
index f6963a5a49..289d089e48 100644
--- a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb
+++ b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb
@@ -22,6 +22,7 @@ describe Spree::Api::V2::Platform::StockLocationSerializer do
backorderable_default: resource.backorderable_default,
city: resource.city,
created_at: resource.created_at,
+ deleted_at: resource.deleted_at,
default: resource.default,
name: resource.name,
phone: resource.phone,
diff --git a/core/app/models/spree/stock_location.rb b/core/app/models/spree/stock_location.rb
index af28e1820d..37748d5e0e 100644
--- a/core/app/models/spree/stock_location.rb
+++ b/core/app/models/spree/stock_location.rb
@@ -14,6 +14,8 @@ module Spree
include Spree::VendorConcern
end
+ acts_as_paranoid
+
has_many :shipments
has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location
has_many :variants, through: :stock_items
diff --git a/core/db/migrate/20240623172111_add_deleted_at_to_spree_stock_locations.rb b/core/db/migrate/20240623172111_add_deleted_at_to_spree_stock_locations.rb
new file mode 100644
index 0000000000..ad495c2b31
--- /dev/null
+++ b/core/db/migrate/20240623172111_add_deleted_at_to_spree_stock_locations.rb
@@ -0,0 +1,6 @@
+class AddDeletedAtToSpreeStockLocations < ActiveRecord::Migration[6.1]
+ def change
+ add_column :spree_stock_locations, :deleted_at, :datetime, if_not_exists: true
+ add_index :spree_stock_locations, :deleted_at, if_not_exists: true
+ end
+end