Class: Spree::PromotionRule

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

Overview

Base class for all promotion rules

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Class Method Details

.for(promotable) ⇒ Object



13
14
15
# File 'core/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 'core/app/models/spree/promotion_rule.rb', line 27

def actionable?(_line_item)
  true
end

#applicable?(_promotable) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

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

#eligibility_errorsObject



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

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

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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

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

#to_partial_pathObject



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

def to_partial_path
  "spree/admin/promotions/rules/#{model_name.element}"
end