Sha256: 12d51c65af0a93d7db450f5cc9824fc21c4333ad3a8d73e32573458fb6c820ce

Contents?: true

Size: 834 Bytes

Versions: 22

Compression:

Stored size: 834 Bytes

Contents

# Base class for all promotion rules
module Spree
  class PromotionRule < ActiveRecord::Base
    belongs_to :promotion, :foreign_key => 'activator_id', :class_name => "Spree::Promotion"

    scope :of_type, lambda {|t| {:conditions => {:type => t}}}

    validate :promotion, :presence => true
    validate :unique_per_activator, :on => :create

    attr_accessible :preferred_operator, :preferred_amount, :product, :product_ids_string, :preferred_match_policy

    def eligible?(order, options = {})
      raise 'eligible? should be implemented in a sub-class of Promotion::PromotionRule'
    end

    private
    def unique_per_activator
      if Spree::PromotionRule.exists?(:activator_id => activator_id, :type => self.class.name)
        errors[:base] << "Promotion already contains this rule type"
      end
    end
 
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
spree_promo-1.3.5 app/models/spree/promotion_rule.rb
spree_promo-1.3.4 app/models/spree/promotion_rule.rb
spree_promo-1.2.5 app/models/spree/promotion_rule.rb
spree_promo-1.3.3 app/models/spree/promotion_rule.rb
spree_promo-1.1.6 app/models/spree/promotion_rule.rb
spree_promo-1.1.5 app/models/spree/promotion_rule.rb
spree_promo-1.2.4 app/models/spree/promotion_rule.rb
spree_promo-1.3.2 app/models/spree/promotion_rule.rb
spree_promo-1.2.3 app/models/spree/promotion_rule.rb
spree_promo-1.3.1 app/models/spree/promotion_rule.rb
spree_promo-1.3.0 app/models/spree/promotion_rule.rb
spree_promo-1.3.0.rc2 app/models/spree/promotion_rule.rb
dup_spree_promo-1.3.0.rc1 app/models/spree/promotion_rule.rb
spree_promo-1.3.0.rc1 app/models/spree/promotion_rule.rb
spree_promo-1.2.2 app/models/spree/promotion_rule.rb
spree_promo-1.1.4 app/models/spree/promotion_rule.rb
spree_promo-1.2.0 app/models/spree/promotion_rule.rb
spree_promo-1.2.0.rc2 app/models/spree/promotion_rule.rb
spree_promo-1.2.0.rc1 app/models/spree/promotion_rule.rb
spree_promo-1.1.3 app/models/spree/promotion_rule.rb