Class: Spree::PromotionRule

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(promotable) ⇒ Object



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

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)


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

def actionable?(_line_item)
  true
end

#applicable?(_promotable) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#eligibility_errorsObject



31
32
33
# File 'app/models/spree/promotion_rule.rb', line 31

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

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

Returns:

  • (Boolean)


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

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

#human_descriptionString

Returns the human description of the promotion rule

Returns:

  • (String)


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

def human_description
  Spree.t("promotion_rule_types.#{key}.description")
end

#human_nameString

Returns the human name of the promotion rule

Returns:

  • (String)

    eg. Currency



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

def human_name
  Spree.t("promotion_rule_types.#{key}.name")
end

#keyString

Returns the key of the promotion rule

Returns:

  • (String)

    eg. currency



52
53
54
# File 'app/models/spree/promotion_rule.rb', line 52

def key
  type.demodulize.underscore
end