Class: Comable::User
Instance Method Summary
collapse
Methods included from CartOwner
#add_cart_item, #cart, #move_cart_item, #remove_cart_item, #reset_cart_item
Instance Method Details
#after_set_user ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'app/models/comable/user.rb', line 73
def after_set_user
return unless current_guest_token
guest_order = Comable::Order.incomplete.preload(:order_items).where(guest_token: current_guest_token).first
return unless guest_order
incomplete_order.inherit!(guest_order)
inherit_cart_items(guest_order)
end
|
#cart_items ⇒ Object
64
65
66
|
# File 'app/models/comable/user.rb', line 64
def cart_items
incomplete_order.order_items
end
|
#human_id ⇒ Object
83
84
85
|
# File 'app/models/comable/user.rb', line 83
def human_id
"##{id}"
end
|
#incomplete_order ⇒ Object
68
69
70
71
|
# File 'app/models/comable/user.rb', line 68
def incomplete_order
@incomplete_order = nil if @incomplete_order.try(:completed?)
@incomplete_order ||= find_incomplete_order || initialize_incomplete_order
end
|
#not_signed_in? ⇒ Boolean
52
53
54
|
# File 'app/models/comable/user.rb', line 52
def not_signed_in?
!signed_in?
end
|
#orders ⇒ Object
Add conditions for the orders association. Override method of the orders association to support Rails 3.x.
32
33
34
|
# File 'app/models/comable/user.rb', line 32
def orders
super.complete.order('completed_at DESC, id DESC')
end
|
#other_addresses ⇒ Object
36
37
38
|
# File 'app/models/comable/user.rb', line 36
def other_addresses
addresses - [bill_address] - [ship_address]
end
|
#reload(*_) ⇒ Object
57
58
59
60
61
62
|
# File 'app/models/comable/user.rb', line 57
def reload(*_)
super.tap do
@cart_items = nil
@incomplete_order = nil
end
end
|
#signed_in? ⇒ Boolean
48
49
50
|
# File 'app/models/comable/user.rb', line 48
def signed_in?
!new_record?
end
|
#update_bill_address_by(bill_address) ⇒ Object
40
41
42
|
# File 'app/models/comable/user.rb', line 40
def update_bill_address_by(bill_address)
update_attributes(bill_address: addresses.find_or_clone(bill_address))
end
|
#update_ship_address_by(ship_address) ⇒ Object
44
45
46
|
# File 'app/models/comable/user.rb', line 44
def update_ship_address_by(ship_address)
update_attributes(ship_address: addresses.find_or_clone(ship_address))
end
|
#with_cookies(cookies) ⇒ Object
25
26
27
28
|
# File 'app/models/comable/user.rb', line 25
def with_cookies(cookies)
@cookies = cookies
self
end
|