Sha256: 60e2d73c8bd3cba7954c0940ef5591aa7def211383fdf2e5e466c4347f890b4a

Contents?: true

Size: 754 Bytes

Versions: 9

Compression:

Stored size: 754 Bytes

Contents

module Spree
  module StockLocations
    module StockItems
      class Create
        prepend Spree::ServiceModule::Base

        def call(stock_location:, variants_scope: Spree::Variant)
          prepared_stock_items = variants_scope.ids.map do |variant_id|
            Hash[
              'stock_location_id', stock_location.id,
              'variant_id', variant_id,
              'backorderable', stock_location.backorderable_default,
              'created_at', Time.current,
              'updated_at', Time.current
            ]
          end
          if prepared_stock_items.any?
            stock_location.stock_items.insert_all(prepared_stock_items)
            variants_scope.touch_all
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.10.0 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.9.0 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.8.3 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.8.2 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.7.3 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.7.2 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.7.1 app/services/spree/stock_locations/stock_items/create.rb
spree_core-4.7.0 app/services/spree/stock_locations/stock_items/create.rb