Sha256: f2a222a54deaf06ac17564490758c93fe89fe48d7d116edfd7d7d9b086ff5126

Contents?: true

Size: 964 Bytes

Versions: 10

Compression:

Stored size: 964 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.where(user_id: self.id).order('created_at DESC').first
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spree_core-2.3.10 config/initializers/user_class_extensions.rb
spree_core-2.3.9 config/initializers/user_class_extensions.rb
spree_core-2.3.8 config/initializers/user_class_extensions.rb
spree_core-2.3.7 config/initializers/user_class_extensions.rb
spree_core-2.4.2 config/initializers/user_class_extensions.rb
spree_core-2.3.6 config/initializers/user_class_extensions.rb
spree_core-2.4.1 config/initializers/user_class_extensions.rb
spree_core-2.4.0 config/initializers/user_class_extensions.rb
spree_core-2.3.5 config/initializers/user_class_extensions.rb
spree_core-2.4.0.rc3 config/initializers/user_class_extensions.rb