Sha256: dd276bef68566e1ae8a69f87a5dbb487fb9fbb6de675a1efb962534edf1f290b

Contents?: true

Size: 743 Bytes

Versions: 2

Compression:

Stored size: 743 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

    attr_accessible :preferred_operator, :preferred_amount

    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

2 entries across 2 versions & 1 rubygems

Version Path
spree_promo-1.1.0.rc2 app/models/spree/promotion_rule.rb
spree_promo-1.1.0.rc1 app/models/spree/promotion_rule.rb