Class: SpreeCmCommissioner::Stock::StockMovementCreator

Inherits:
BaseInteractor
  • Object
show all
Defined in:
app/interactors/spree_cm_commissioner/stock/stock_movement_creator.rb

Instance Method Summary collapse

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/interactors/spree_cm_commissioner/stock/stock_movement_creator.rb', line 6

def call
  variant = current_store.variants.find(variant_id)

  return context.fail!(message: Spree.t(:doesnt_track_inventory)) unless variant.track_inventory?

  stock_location = Spree::StockLocation.find(stock_location_id)
  stock_movement = stock_location.stock_movements.build(stock_movement_params)
  stock_movement.stock_item = stock_location.set_up_stock_item(variant)

  if stock_movement.save
    adjust_inventory_items_async(variant_id, stock_movement.quantity)
    context.stock_movement = stock_movement
  else
    context.fail!(message: stock_movement.errors.full_messages.join(', '))
  end
end