Class: Comable::Customer
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
80
81
82
83
84
85
86
87
88
|
# File 'app/models/comable/customer.rb', line 80
def after_set_user
return unless current_guest_token
guest_order = Comable::Order.incomplete.preload(:order_details).where(guest_token: current_guest_token).first
return unless guest_order
inherit_order_state(guest_order)
inherit_cart_items(guest_order)
end
|
#cart_items ⇒ Object
64
65
66
|
# File 'app/models/comable/customer.rb', line 64
def cart_items
@cart_items ||= incomplete_order.order_details
end
|
#human_id ⇒ Object
90
91
92
|
# File 'app/models/comable/customer.rb', line 90
def human_id
"##{id}"
end
|
#incomplete_order ⇒ Object
68
69
70
|
# File 'app/models/comable/customer.rb', line 68
def incomplete_order
@incomplete_order ||= find_incomplete_order || initialize_incomplete_order
end
|
#not_signed_in? ⇒ Boolean
52
53
54
|
# File 'app/models/comable/customer.rb', line 52
def not_signed_in?
!signed_in?
end
|
#order(order_params = {}) ⇒ Object
72
73
74
75
76
77
78
|
# File 'app/models/comable/customer.rb', line 72
def order(order_params = {})
Rails.logger.debug '[DEPRECATED] Comable::Customer#order is deprecated. Please use Comable::Order#next_state method.'
incomplete_order.attributes = order_params
incomplete_order.state = 'complete'
incomplete_order.complete!
incomplete_order.tap { reload }
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/customer.rb', line 32
def orders
super.complete.order('completed_at DESC, id DESC')
end
|
#other_addresses ⇒ Object
36
37
38
|
# File 'app/models/comable/customer.rb', line 36
def other_addresses
addresses - [bill_address] - [ship_address]
end
|
#reload(*_) ⇒ Object
57
58
59
60
61
62
|
# File 'app/models/comable/customer.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/customer.rb', line 48
def signed_in?
!new_record?
end
|
#update_bill_address_by(bill_address) ⇒ Object
40
41
42
|
# File 'app/models/comable/customer.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/customer.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/customer.rb', line 25
def with_cookies(cookies)
@cookies = cookies
self
end
|