11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/services/spree/stock_locations/stock_levels/create.rb', line 11
def call(stock_location:, variants_scope: nil)
variant_ids = propagatable_variants(stock_location, variants_scope).ids
prepared_stock_levels = variant_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_levels.any?
stock_location.stock_levels.insert_all(prepared_stock_levels)
Spree::Variant.where(id: variant_ids).touch_all
end
end
|