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::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
13 14 15 |
# File '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
27 28 29 |
# File 'app/models/spree/promotion_rule.rb', line 27 def actionable?(_line_item) true end |
#applicable?(_promotable) ⇒ Boolean
17 18 19 |
# File 'app/models/spree/promotion_rule.rb', line 17 def applicable?(_promotable) raise 'applicable? should be implemented in a sub-class of Spree::PromotionRule' end |
#eligibility_errors ⇒ Object
31 32 33 |
# File 'app/models/spree/promotion_rule.rb', line 31 def eligibility_errors @eligibility_errors ||= ActiveModel::Errors.new(self) end |
#eligible?(_promotable, _options = {}) ⇒ Boolean
21 22 23 |
# File 'app/models/spree/promotion_rule.rb', line 21 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
45 46 47 |
# File 'app/models/spree/promotion_rule.rb', line 45 def human_description Spree.t("promotion_rule_types.#{key}.description") end |
#human_name ⇒ String
Returns the human name of the promotion rule
38 39 40 |
# File 'app/models/spree/promotion_rule.rb', line 38 def human_name Spree.t("promotion_rule_types.#{key}.name") end |
#key ⇒ String
Returns the key of the promotion rule
52 53 54 |
# File 'app/models/spree/promotion_rule.rb', line 52 def key type.demodulize.underscore end |