Class: Comable::Order
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Order
show all
- Includes:
- Checkout, Liquidable, Associations, Callbacks, DeprecatedMethods, Morrisable, Scopes, Validations, Ransackable
- Defined in:
- app/models/comable/order.rb,
app/models/comable/order/scopes.rb,
app/models/comable/order/callbacks.rb,
app/models/comable/order/morrisable.rb,
app/models/comable/order/validations.rb,
app/models/comable/order/associations.rb,
app/models/comable/order/deprecated_methods.rb
Defined Under Namespace
Modules: Associations, Callbacks, DeprecatedMethods, Morrisable, Scopes, Validations
Instance Attribute Summary collapse
Instance Method Summary
collapse
#shipment, #shipment=
Methods included from Callbacks
#clone_addresses_from_user, #clone_addresses_to_user, #copy_ship_address_from_bill_address, #generate_code, #generate_guest_token
Methods included from Checkout
#allow_cancel?, #allow_return?, #delivery_required?, #orderer_required?, #payment_required?, #shipment_required?, #stated?
Instance Attribute Details
#same_as_bill_address ⇒ Object
132
133
134
|
# File 'app/models/comable/order.rb', line 132
def same_as_bill_address
@same_as_bill_address.nil? ? bill_address == ship_address : @same_as_bill_address
end
|
Instance Method Details
#assign_inventory_units_to_shipments ⇒ Object
58
59
60
61
62
|
# File 'app/models/comable/order.rb', line 58
def assign_inventory_units_to_shipments
reset_shipments
self.shipments = Comable::Inventory::Coordinator.new(self).shipments
save!
end
|
#can_ship? ⇒ Boolean
124
125
126
|
# File 'app/models/comable/order.rb', line 124
def can_ship?
shipments.any?(&:can_ship?)
end
|
#complete! ⇒ Object
Also known as:
complete
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/models/comable/order.rb', line 31
def complete!
ActiveRecord::Base.transaction do
run_callbacks :complete do
self.attributes = current_attributes
order_items.each(&:complete)
save!
payment.next_state! if payment
shipments.each(&:next_state!)
touch(:completed_at)
end
end
end
|
#completed? ⇒ Boolean
107
108
109
|
# File 'app/models/comable/order.rb', line 107
def completed?
completed_at?
end
|
#current_item_total_price ⇒ Object
73
74
75
|
# File 'app/models/comable/order.rb', line 73
def current_item_total_price
order_items.to_a.sum(&:current_subtotal_price)
end
|
#current_payment_fee ⇒ Object
Get the current payment fee
88
89
90
|
# File 'app/models/comable/order.rb', line 88
def current_payment_fee
payment.try(:current_fee) || 0
end
|
#current_shipment_fee ⇒ Object
83
84
85
|
# File 'app/models/comable/order.rb', line 83
def current_shipment_fee
shipments.to_a.sum(&:current_fee)
end
|
#current_total_price ⇒ Object
93
94
95
|
# File 'app/models/comable/order.rb', line 93
def current_total_price
current_item_total_price + current_payment_fee + current_shipment_fee
end
|
#draft? ⇒ Boolean
111
112
113
|
# File 'app/models/comable/order.rb', line 111
def draft?
read_attribute(:draft)
end
|
#inherit!(order) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'app/models/comable/order.rb', line 98
def inherit!(order)
self.bill_address ||= order.bill_address
self.ship_address ||= order.ship_address
self.payment ||= order.payment
self.shipments = order.shipments if shipments.empty?
stated?(order.state) ? save! : next_state!
end
|
#item_total_price ⇒ Object
78
79
80
|
# File 'app/models/comable/order.rb', line 78
def item_total_price
order_items.to_a.sum(&:subtotal_price)
end
|
#paid? ⇒ Boolean
115
116
117
|
# File 'app/models/comable/order.rb', line 115
def paid?
payment ? payment.completed? : true
end
|
#reset_shipments ⇒ Object
64
65
66
|
# File 'app/models/comable/order.rb', line 64
def reset_shipments
shipments.destroy_all
end
|
#restock! ⇒ Object
50
51
52
|
# File 'app/models/comable/order.rb', line 50
def restock!
shipments.each(&:restock!)
end
|
#ship! ⇒ Object
128
129
130
|
# File 'app/models/comable/order.rb', line 128
def ship!
shipments.with_state(:ready).each(&:ship!)
end
|
#shipped? ⇒ Boolean
119
120
121
122
|
# File 'app/models/comable/order.rb', line 119
def shipped?
return true if shipments.empty?
shipments.all?(&:completed?)
end
|
#unstock! ⇒ Object
54
55
56
|
# File 'app/models/comable/order.rb', line 54
def unstock!
shipments.each(&:unstock!)
end
|
#unstocked_items ⇒ Object
68
69
70
|
# File 'app/models/comable/order.rb', line 68
def unstocked_items
order_items.to_a.select(&:unstocked?)
end
|