Class: Spree::PromotionRule
- Inherits:
-
Object
- Object
- Spree::PromotionRule
show all
- Defined in:
- app/models/spree/promotion_rule.rb
Direct Known Subclasses
Spree::Promotion::Rules::Country, Spree::Promotion::Rules::Currency, Spree::Promotion::Rules::CustomerGroup, Spree::Promotion::Rules::FirstOrder, Spree::Promotion::Rules::ItemTotal, Spree::Promotion::Rules::OneUsePerUser, Spree::Promotion::Rules::OptionValue, Spree::Promotion::Rules::Product, Spree::Promotion::Rules::Taxon, Spree::Promotion::Rules::User, Spree::Promotion::Rules::UserLoggedIn
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.additional_permitted_attributes ⇒ Object
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_description ⇒ Object
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_name ⇒ Object
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
37
38
39
|
# File 'app/models/spree/promotion_rule.rb', line 37
def actionable?(_line_item)
true
end
|
#applicable?(_promotable) ⇒ 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_errors ⇒ Object
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
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_description ⇒ Object
54
|
# File 'app/models/spree/promotion_rule.rb', line 54
def human_description = self.class.human_description
|
#human_name ⇒ Object
53
|
# File 'app/models/spree/promotion_rule.rb', line 53
def human_name = self.class.human_name
|
#key ⇒ String
Returns the key of the promotion rule
59
60
61
|
# File 'app/models/spree/promotion_rule.rb', line 59
def key
self.class.api_type
end
|