Class: Spree::FulfilmentChanger

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/spree/fulfilment_changer.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ FulfilmentChanger

Returns a new instance of FulfilmentChanger.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/spree/fulfilment_changer.rb', line 11

def initialize(params = {})
  @current_stock_location = params[:current_stock_location]
  @desired_stock_location = params[:desired_stock_location]
  @current_shipment       = params[:current_shipment]
  @desired_shipment       = params[:desired_shipment]
  @variant                = params[:variant]
  @quantity               = params[:quantity]
  @available_quantity     = [
    desired_stock_location.try(:count_on_hand, variant).to_i,
    current_quantity
  ].max
end

Instance Method Details

#run!Object



24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/spree/fulfilment_changer.rb', line 24

def run!
  return false if invalid?

  desired_shipment.save! if desired_shipment.new_record?

  handle_stock
  reload_shipment_inventory_units
  after_process_shipments

  true
end