Class: Spree::PromotionRule

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/promotion_rule.rb

Overview

Base class for all promotion rules

Direct Known Subclasses

Spree::Promotion::Rules::FirstOrder, Spree::Promotion::Rules::FirstRepeatPurchaseSince, Spree::Promotion::Rules::ItemTotal, Spree::Promotion::Rules::NthOrder, Spree::Promotion::Rules::OneUsePerUser, Spree::Promotion::Rules::OptionValue, Spree::Promotion::Rules::Product, Spree::Promotion::Rules::Taxon, Spree::Promotion::Rules::User, Spree::Promotion::Rules::UserLoggedIn, Spree::Promotion::Rules::UserRole

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

+ (Object) for(promotable)



11
12
13
# File 'app/models/spree/promotion_rule.rb', line 11

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

Instance Method Details

- (Boolean) actionable?(_line_item)

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)


25
26
27
# File 'app/models/spree/promotion_rule.rb', line 25

def actionable?(_line_item)
  true
end

- (Boolean) applicable?(_promotable)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


15
16
17
# File 'app/models/spree/promotion_rule.rb', line 15

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

- (Object) eligibility_errors



29
30
31
# File 'app/models/spree/promotion_rule.rb', line 29

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

- (Boolean) eligible?(_promotable, _options = {})

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

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