Class: Comable::Customer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Customer
show all
- Includes:
- CartOwner, Decoratable
- Defined in:
- app/models/comable/customer.rb
Instance Method Summary
collapse
Methods included from CartOwner
#add_cart_item, #cart, #remove_cart_item, #reset_cart_item
included
Constructor Details
#initialize(*args) ⇒ Customer
Returns a new instance of Customer.
9
10
11
12
13
14
15
16
17
18
|
# File 'app/models/comable/customer.rb', line 9
def initialize(*args)
obj = args.first
case obj.class.name
when /Cookies/
@cookies = obj
super()
else
super
end
end
|
Instance Method Details
#cart_items ⇒ Object
37
38
39
|
# File 'app/models/comable/customer.rb', line 37
def cart_items
incomplete_order.order_deliveries.first.order_details
end
|
#incomplete_order ⇒ Object
41
42
43
|
# File 'app/models/comable/customer.rb', line 41
def incomplete_order
@incomplete_order ||= initialize_incomplete_order
end
|
#logged_in? ⇒ Boolean
20
21
22
|
# File 'app/models/comable/customer.rb', line 20
def logged_in?
!new_record?
end
|
#not_logged_in? ⇒ Boolean
24
25
26
|
# File 'app/models/comable/customer.rb', line 24
def not_logged_in?
!logged_in?
end
|
#order(order_params = {}) ⇒ Object
50
51
52
53
|
# File 'app/models/comable/customer.rb', line 50
def order(order_params = {})
incomplete_order.attributes = order_params
incomplete_order.complete.tap { |completed_flag| reset_cart if completed_flag }
end
|
#preorder(order_params = {}) ⇒ Object
45
46
47
48
|
# File 'app/models/comable/customer.rb', line 45
def preorder(order_params = {})
incomplete_order.attributes = order_params
incomplete_order.precomplete
end
|
#reset_cart ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'app/models/comable/customer.rb', line 28
def reset_cart
return unless incomplete_order
incomplete_order.destroy if incomplete_order.incomplete?
@incomplete_order = nil
end
|