Class: Spree::Exchange
- Inherits:
-
Object
show all
- Defined in:
- app/models/spree/exchange.rb
Defined Under Namespace
Classes: UnableToCreateShipments
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(order, reimbursement_objects) ⇒ Exchange
Returns a new instance of Exchange.
5
6
7
8
|
# File 'app/models/spree/exchange.rb', line 5
def initialize(order, reimbursement_objects)
@order = order
@reimbursement_objects = reimbursement_objects
end
|
Class Method Details
.model_name ⇒ Object
41
42
43
|
# File 'app/models/spree/exchange.rb', line 41
def self.model_name
Spree::Exchange
end
|
.param_key ⇒ Object
37
38
39
|
# File 'app/models/spree/exchange.rb', line 37
def self.param_key
"spree_exchange"
end
|
Instance Method Details
#description ⇒ Object
10
11
12
13
14
|
# File 'app/models/spree/exchange.rb', line 10
def description
@reimbursement_objects.map do |reimbursement_object|
"#{reimbursement_object.variant.options_text} => #{reimbursement_object.exchange_variant.options_text}"
end.join(" | ")
end
|
#display_amount ⇒ Object
16
17
18
|
# File 'app/models/spree/exchange.rb', line 16
def display_amount
Spree::Money.new @reimbursement_objects.map(&:total).sum
end
|
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/models/spree/exchange.rb', line 20
def perform!
shipments = Spree::Stock::Coordinator.new(@order, @reimbursement_objects.map(&:build_exchange_inventory_unit)).shipments
if shipments.flat_map(&:inventory_units).size != @reimbursement_objects.size
raise UnableToCreateShipments.new("Could not generate shipments for all items. Out of stock?")
end
@order.shipments += shipments
@order.save!
shipments.each do |shipment|
shipment.update!(@order)
shipment.finalize!
end
end
|
#to_key ⇒ Object
33
34
35
|
# File 'app/models/spree/exchange.rb', line 33
def to_key
nil
end
|