Class: Spree::PromotionRule
- Inherits:
-
Object
- Object
- Spree::PromotionRule
- 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
-
#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.
- #applicable?(_promotable) ⇒ Boolean
- #eligibility_errors ⇒ Object
- #eligible?(_promotable, _options = {}) ⇒ Boolean
-
#human_description ⇒ String
Returns the human description of the promotion rule.
-
#human_name ⇒ String
Returns the human name of the promotion rule.
-
#key ⇒ String
Returns the key of the promotion rule.
Class Method Details
.for(promotable) ⇒ Object
15 16 17 |
# File 'app/models/spree/promotion_rule.rb', line 15 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
29 30 31 |
# File 'app/models/spree/promotion_rule.rb', line 29 def actionable?(_line_item) true end |
#applicable?(_promotable) ⇒ Boolean
19 20 21 |
# File 'app/models/spree/promotion_rule.rb', line 19 def applicable?(_promotable) raise 'applicable? should be implemented in a sub-class of Spree::PromotionRule' end |
#eligibility_errors ⇒ Object
33 34 35 |
# File 'app/models/spree/promotion_rule.rb', line 33 def eligibility_errors @eligibility_errors ||= ActiveModel::Errors.new(self) end |
#eligible?(_promotable, _options = {}) ⇒ Boolean
23 24 25 |
# File 'app/models/spree/promotion_rule.rb', line 23 def eligible?(_promotable, = {}) raise 'eligible? should be implemented in a sub-class of Spree::PromotionRule' end |
#human_description ⇒ String
Returns the human description of the promotion rule
47 48 49 |
# File 'app/models/spree/promotion_rule.rb', line 47 def human_description Spree.t("promotion_rule_types.#{key}.description") end |
#human_name ⇒ String
Returns the human name of the promotion rule
40 41 42 |
# File 'app/models/spree/promotion_rule.rb', line 40 def human_name Spree.t("promotion_rule_types.#{key}.name") end |
#key ⇒ String
Returns the key of the promotion rule
54 55 56 |
# File 'app/models/spree/promotion_rule.rb', line 54 def key type.demodulize.underscore end |