diff --git a/app/models/spree/stock_location.rb b/app/models/spree/stock_location.rb index 7b71a099e5..77b08e5855 100644 --- a/app/models/spree/stock_location.rb +++ b/app/models/spree/stock_location.rb @@ -18,10 +18,6 @@ module Spree after_create :create_stock_items # Wrapper for creating a new stock item respecting the backorderable config - def propagate_variant(variant) - stock_items.create!(variant:) - end - def stock_item(variant) stock_items.where(variant_id: variant).order(:id).first end @@ -57,7 +53,7 @@ module Spree private def create_stock_items - Variant.find_each { |variant| propagate_variant(variant) } + Variant.find_each { |variant| stock_items.create!(variant:) } end end end diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 5cacf65a9c..4425c24523 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -243,7 +243,7 @@ module Spree return unless stock_items.empty? StockLocation.find_each do |stock_location| - stock_location.propagate_variant(self) + stock_items.create!(stock_location:) end end diff --git a/spec/models/spree/stock_location_spec.rb b/spec/models/spree/stock_location_spec.rb index 216e0f8cac..fd01212caa 100644 --- a/spec/models/spree/stock_location_spec.rb +++ b/spec/models/spree/stock_location_spec.rb @@ -20,7 +20,7 @@ module Spree subject { StockLocation.new(name: "testing") } specify do - expect(subject).to receive(:propagate_variant).at_least(:once) + expect(subject.stock_items).to receive(:create!).at_least(:once) subject.save! end end