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

.additional_permitted_attributesObject

Per-subclass permitted attributes beyond ‘type` and `preferences`. Override in STI subclasses that accept association IDs (e.g. Rules::Product needs `product_ids`). The Admin API merges these into its `params.permit(…)` allowlist.



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

def self.additional_permitted_attributes
  []
end

.for(promotable) ⇒ Object



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

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

.human_descriptionObject



49
50
51
# File 'app/models/spree/promotion_rule.rb', line 49

def self.human_description
  Spree.t("promotion_rule_types.#{api_type}.description", default: '')
end

.human_nameObject



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

def self.human_name
  Spree.t("promotion_rule_types.#{api_type}.name", default: api_type.titleize)
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)


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

def actionable?(_line_item)
  true
end

#applicable?(_promotable) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#eligibility_errorsObject



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

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

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

Returns:

  • (Boolean)


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

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

#human_descriptionObject



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

def human_description = self.class.human_description

#human_nameObject



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

def human_name = self.class.human_name

#keyString

Returns the key of the promotion rule

Returns:

  • (String)

    eg. currency



59
60
61
# File 'app/models/spree/promotion_rule.rb', line 59

def key
  self.class.api_type
end