Class: Spree::PromotionRule
- Inherits:
-
Object
- Object
- Spree::PromotionRule
- Includes:
- TypeLabels
- Defined in:
- app/models/spree/promotion_rule.rb
Direct Known Subclasses
Spree::Promotion::Rules::Category, Spree::Promotion::Rules::Channel, Spree::Promotion::Rules::Country, Spree::Promotion::Rules::Currency, Spree::Promotion::Rules::CustomerGroup, Spree::Promotion::Rules::FirstOrder, Spree::Promotion::Rules::ItemTotal, Spree::Promotion::Rules::Market, Spree::Promotion::Rules::OneUsePerUser, Spree::Promotion::Rules::OptionValue, Spree::Promotion::Rules::Product, 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
-
#key ⇒ String
Returns the key of the promotion rule.
Methods included from TypeLabels
#human_description, #human_name
Class Method Details
.for(promotable) ⇒ Object
20 21 22 |
# File 'app/models/spree/promotion_rule.rb', line 20 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
34 35 36 |
# File 'app/models/spree/promotion_rule.rb', line 34 def actionable?(_line_item) true end |
#applicable?(promotable) ⇒ Boolean
24 25 26 |
# File 'app/models/spree/promotion_rule.rb', line 24 def applicable?(promotable) promotable.is_a?(Spree::Order) || promotable.is_a?(Spree::Cart) end |
#eligibility_errors ⇒ Object
38 39 40 |
# File 'app/models/spree/promotion_rule.rb', line 38 def eligibility_errors @eligibility_errors ||= ActiveModel::Errors.new(self) end |
#eligible?(_promotable, _options = {}) ⇒ Boolean
28 29 30 |
# File 'app/models/spree/promotion_rule.rb', line 28 def eligible?(_promotable, = {}) raise 'eligible? should be implemented in a sub-class of Spree::PromotionRule' end |
#key ⇒ String
Returns the key of the promotion rule
45 46 47 |
# File 'app/models/spree/promotion_rule.rb', line 45 def key self.class.api_type end |