Class: Comable::User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CartOwner, Liquidable, Ransackable, RoleOwner
Defined in:
app/models/comable/user.rb

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_userObject



80
81
82
83
84
85
86
87
88
# File 'app/models/comable/user.rb', line 80

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_itemsObject



71
72
73
# File 'app/models/comable/user.rb', line 71

def cart_items
  incomplete_order.order_items
end

#human_idObject



90
91
92
# File 'app/models/comable/user.rb', line 90

def human_id
  "##{id}"
end

#incomplete_orderObject



75
76
77
78
# File 'app/models/comable/user.rb', line 75

def incomplete_order
  @incomplete_order = nil if @incomplete_order.try(:completed?)
  @incomplete_order ||= find_incomplete_order || initialize_incomplete_order
end

#not_signed_in?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/comable/user.rb', line 59

def not_signed_in?
  !signed_in?
end

#ordersObject

Add conditions for the orders association. Override method of the orders association to support Rails 3.x.



39
40
41
# File 'app/models/comable/user.rb', line 39

def orders
  super.complete.order('completed_at DESC, id DESC')
end

#other_addressesObject



43
44
45
# File 'app/models/comable/user.rb', line 43

def other_addresses
  addresses - [bill_address] - [ship_address]
end

#reload(*_) ⇒ Object

TODO: Add a test case



64
65
66
67
68
69
# File 'app/models/comable/user.rb', line 64

def reload(*_)
  super.tap do
    @cart_items = nil
    @incomplete_order = nil
  end
end

#signed_in?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/comable/user.rb', line 55

def signed_in?
  !new_record?
end

#update_bill_address_by(bill_address) ⇒ Object



47
48
49
# File 'app/models/comable/user.rb', line 47

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



51
52
53
# File 'app/models/comable/user.rb', line 51

def update_ship_address_by(ship_address)
  update_attributes(ship_address: addresses.find_or_clone(ship_address))
end

#with_cookies(cookies) ⇒ Object



32
33
34
35
# File 'app/models/comable/user.rb', line 32

def with_cookies(cookies)
  @cookies = cookies
  self
end