Sha256: cb562d0f418bd67ebc190a4bdd2fc0c49f9019c6d609df25ce9abdcb5895089c

Contents?: true

Size: 751 Bytes

Versions: 3

Compression:

Stored size: 751 Bytes

Contents

module Spree
  class Promotion
    module Rules
      class User < PromotionRule
        belongs_to :user, class_name: Spree::UserClassHandle.new

        has_and_belongs_to_many :users, class_name: Spree::UserClassHandle.new,
          join_table: 'spree_promotion_rules_users',
          foreign_key: 'promotion_rule_id',
          association_foreign_key: :user_id

        def applicable?(promotable)
          promotable.is_a?(Spree::Order)
        end

        def eligible?(order, options = {})
          users.include?(order.user)
        end

        def user_ids_string
          user_ids.join(',')
        end

        def user_ids_string=(s)
          self.user_ids = s.to_s.split(',').map(&:strip)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_core-1.0.0.rc1 app/models/spree/promotion/rules/user.rb
solidus_core-1.0.0.pre3 app/models/spree/promotion/rules/user.rb
solidus_core-1.0.0.pre2 app/models/spree/promotion/rules/user.rb