Sha256: f9d7a5cec0da6ba5247e8041e28571a34489dc50fe9787b4baafff815ab7e570

Contents?: true

Size: 917 Bytes

Versions: 11

Compression:

Stored size: 917 Bytes

Contents

Spree::Core::Engine.config.to_prepare do
  if Spree.user_class
    Spree.user_class.class_eval do
      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(:created_by_id => self.id).order('created_at DESC').first
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_core-2.1.12 config/initializers/user_class_extensions.rb
spree_core-2.1.11 config/initializers/user_class_extensions.rb
spree_core-2.1.10 config/initializers/user_class_extensions.rb
spree_core-2.1.9 config/initializers/user_class_extensions.rb
spree_core-2.1.8 config/initializers/user_class_extensions.rb
spree_core-2.1.7 config/initializers/user_class_extensions.rb
spree_core-2.1.6 config/initializers/user_class_extensions.rb
spree_core-2.2.0 config/initializers/user_class_extensions.rb
spree_core-2.1.5 config/initializers/user_class_extensions.rb
spree_core-2.1.4 config/initializers/user_class_extensions.rb
spree_core-2.1.3 config/initializers/user_class_extensions.rb