Module: Spree::UserMethods Private

Extended by:
ActiveSupport::Concern
Includes:
UserAddressBook, UserApiAuthentication, UserPaymentSource, UserReporting
Included in:
LegacyUser
Defined in:
app/models/concerns/spree/user_methods.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods included from UserPaymentSource

#default_credit_card, #payment_sources

Methods included from UserAddressBook

#bill_address=, #bill_address_attributes=, #default_address=, #default_address_attributes=, #mark_default_address, #persist_order_address, #remove_from_address_book, #save_in_address_book, #ship_address=

Methods included from UserReporting

#average_order_value, #lifetime_value, #order_count

Methods included from DisplayMoney

#money_methods

Methods included from UserApiAuthentication

#clear_spree_api_key, #clear_spree_api_key!, #generate_spree_api_key, #generate_spree_api_key!

Instance Method Details

#auto_generate_spree_api_keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
49
50
51
52
# File 'app/models/concerns/spree/user_methods.rb', line 46

def auto_generate_spree_api_key
  return if !respond_to?(:spree_api_key) || spree_api_key.present?

  if Spree::Config.generate_api_key_for_all_roles || (spree_roles.map(&:name) & Spree::Config.roles_for_auto_api_key).any?
    generate_spree_api_key!
  end
end

#has_spree_role?(role_in_question) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

has_spree_role? simply needs to return true or false whether a user has a role or not.

Returns:

  • (Boolean)


42
43
44
# File 'app/models/concerns/spree/user_methods.rb', line 42

def has_spree_role?(role_in_question)
  spree_roles.any? { |role| role.name == role_in_question.to_s }
end

#last_incomplete_spree_order(store: nil, only_frontend_viewable: true) ⇒ Spree::Order

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

since the customer's last complete order.

Returns:

  • (Spree::Order)

    the most-recently-created incomplete order



56
57
58
59
60
61
62
63
64
# File 'app/models/concerns/spree/user_methods.rb', line 56

def last_incomplete_spree_order(store: nil, only_frontend_viewable: true)
  self_orders = orders
  self_orders = self_orders.where(frontend_viewable: true) if only_frontend_viewable
  self_orders = self_orders.where(store: store) if store
  self_orders = self_orders.where('updated_at > ?', Spree::Config.completable_order_updated_cutoff_days.days.ago) if Spree::Config.completable_order_updated_cutoff_days
  self_orders = self_orders.where('created_at > ?', Spree::Config.completable_order_created_cutoff_days.days.ago) if Spree::Config.completable_order_created_cutoff_days
  last_order = self_orders.order(:created_at).last
  last_order unless last_order.try!(:completed?)
end

#total_available_store_creditObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'app/models/concerns/spree/user_methods.rb', line 66

def total_available_store_credit
  store_credits.reload.to_a.sum(&:amount_remaining)
end

#walletObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'app/models/concerns/spree/user_methods.rb', line 37

def wallet
  Spree::Wallet.new(self)
end