Sha256: 1e20ee786dd93357e26078d38c899b6dd35c0f935dc8d534f08dabd1ab6add3f

Contents?: true

Size: 683 Bytes

Versions: 7

Compression:

Stored size: 683 Bytes

Contents

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

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

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

    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

7 entries across 7 versions & 1 rubygems

Version Path
spree_promo-1.0.4 app/models/spree/promotion_rule.rb
spree_promo-1.0.3 app/models/spree/promotion_rule.rb
spree_promo-1.0.2 app/models/spree/promotion_rule.rb
spree_promo-1.0.1 app/models/spree/promotion_rule.rb
spree_promo-1.0.0 app/models/spree/promotion_rule.rb
spree_promo-1.0.0.rc4 app/models/spree/promotion_rule.rb
spree_promo-1.0.0.rc3 app/models/spree/promotion_rule.rb