Sha256: f31e2a034900a2577dfc17fba859e520c411ed2c2a824e5c1b06a958bcd83601

Contents?: true

Size: 923 Bytes

Versions: 7

Compression:

Stored size: 923 Bytes

Contents

Spree::Core::Engine.config.to_prepare do
  if Spree.user_class
    Spree.user_class.class_eval do
      include Spree::Core::UserBanners
      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

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-1.3.5 config/initializers/user_class_extensions.rb
spree_core-1.3.4 config/initializers/user_class_extensions.rb
spree_core-2.0.3 config/initializers/user_class_extensions.rb
spree_core-2.0.2 config/initializers/user_class_extensions.rb
spree_core-2.0.1 config/initializers/user_class_extensions.rb
spree_core-2.0.0 config/initializers/user_class_extensions.rb
spree_core-2.0.0.rc1 config/initializers/user_class_extensions.rb