Class: Spree::PromotionRule

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TypeLabels

#human_description, #human_name

Class Method Details

.for(promotable) ⇒ Object



20
21
22
# File 'app/models/spree/promotion_rule.rb', line 20

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)


34
35
36
# File 'app/models/spree/promotion_rule.rb', line 34

def actionable?(_line_item)
  true
end

#applicable?(promotable) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#eligibility_errors ⇒ Object



38
39
40
# File 'app/models/spree/promotion_rule.rb', line 38

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

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

Returns:

  • (Boolean)


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

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

#key ⇒ String

Returns the key of the promotion rule

Returns:

  • (String) —

    eg. currency



45
46
47
# File 'app/models/spree/promotion_rule.rb', line 45

def key
  self.class.api_type
end