Sha256: 53ddd32923ea6ee0a19e097bdce9745d087d77170d85db3fc4956219b38d8e50

Contents?: true

Size: 940 Bytes

Versions: 6

Compression:

Stored size: 940 Bytes

Contents

Spree::Core::Engine.config.to_prepare do
  if Spree.user_class
    Spree.user_class.class_eval do

      include Spree::UserApiAuthentication
      include Spree::UserReporting

      has_and_belongs_to_many :spree_roles,
                              join_table: 'spree_roles_users',
                              foreign_key: "user_id",
                              class_name: "Spree::Role"

      has_many :spree_orders, foreign_key: "user_id", class_name: "Spree::Order"

      belongs_to :ship_address, class_name: 'Spree::Address'
      belongs_to :bill_address, class_name: 'Spree::Address'

      # has_spree_role? simply needs to return true or false whether a user has a role or not.
      def has_spree_role?(role_in_question)
        spree_roles.where(name: role_in_question.to_s).any?
      end

      def last_incomplete_spree_order
        spree_orders.incomplete.order('created_at DESC').first
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-2.4.7 config/initializers/user_class_extensions.rb
spree_core-2.4.6 config/initializers/user_class_extensions.rb
spree_core-2.4.5 config/initializers/user_class_extensions.rb
spree_core-2.4.4 config/initializers/user_class_extensions.rb
spree_core-3.0.0.rc1 config/initializers/user_class_extensions.rb
spree_core-2.4.3 config/initializers/user_class_extensions.rb