Class: Spree::PromotionRule

Inherits:
Base
  • Object
show all
Includes:
Spree::Preferences::Persistable
Defined in:
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

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Class Method Details

.for(promotable) ⇒ Object


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

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)

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

def actionable?(_line_item)
  true
end

#applicable?(_promotable) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

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

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

#eligibility_errorsObject


40
41
42
# File 'app/models/spree/promotion_rule.rb', line 40

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

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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

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

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

#preload_relationsObject


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

def preload_relations
  []
end

#to_partial_pathObject


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

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