Class: Spree::PromotionRule

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/promotion_rule.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Spree::Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.for(promotable) ⇒ Object



10
11
12
# File 'app/models/spree/promotion_rule.rb', line 10

def self.for(promotable)
  all.select { |rule| rule.applicable?(promotable) }
end

Instance Method Details

#actionable?(_line_item) ⇒ Boolean

This states if a promotion can be applied to the specified line item It is true by default, but can be overridden by promotion rules to provide conditions

Returns:

  • (Boolean)


24
25
26
# File 'app/models/spree/promotion_rule.rb', line 24

def actionable?(_line_item)
  true
end

#applicable?(_promotable) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/spree/promotion_rule.rb', line 14

def applicable?(_promotable)
  raise 'applicable? should be implemented in a sub-class of Spree::PromotionRule'
end

#eligibility_errorsObject



28
29
30
# File 'app/models/spree/promotion_rule.rb', line 28

def eligibility_errors
  @eligibility_errors ||= ActiveModel::Errors.new(self)
end

#eligible?(_promotable, _options = {}) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/spree/promotion_rule.rb', line 18

def eligible?(_promotable, _options = {})
  raise 'eligible? should be implemented in a sub-class of Spree::PromotionRule'
end