Class: Spree::PriceRule

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.contextual? ⇒ Boolean

Whether this rule narrows by something about the purchase rather than about the buyer. A catalog-owned price list has already been matched on audience by the time the resolver holds it — the catalog assignment is what selected it — so only contextual rules still have a question left to answer there. Quantity is the case that matters: no assignment can express "when they buy ten", because that is a property of the order line and not of the customer.

A predicate rather than a list of type names, so a rule kind an extension registers can declare itself contextual too (docs/plans/6.0-price-list-automatic-pricing.md).

Returns:

  • (Boolean)


32
33
34
# File 'app/models/spree/price_rule.rb', line 32

def self.contextual?
  false
end

.description ⇒ String

Returns the description of the price rule

Returns:

  • (String)


63
64
65
# File 'app/models/spree/price_rule.rb', line 63

def self.description
  ''
end

.human_name ⇒ String

Returns the human name of the price rule

Returns:

  • (String)


57
58
59
# File 'app/models/spree/price_rule.rb', line 57

def self.human_name
  name.demodulize.titleize
end

.superseded? ⇒ Boolean

Whether a better mechanism has replaced this rule kind. Superseded kinds are grandfathered — existing rules keep matching indefinitely — but they are flagged in types discovery so pickers stop offering them to new setups (docs/plans/6.0-catalog-agreement-rework.md).

Returns:

  • (Boolean)


51
52
53
# File 'app/models/spree/price_rule.rb', line 51

def self.superseded?
  false
end

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns true if the price rule is applicable to the context

Parameters:

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def applicable?(context)
  raise NotImplementedError, "#{self.class.name} must implement #applicable?"
end

#contextual? ⇒ Boolean

Instance-side reader, so rules can be classified per row (price_rules.select(&:contextual?)). A kind whose answer depends on how it is configured overrides this.

Returns:

  • (Boolean)


41
42
43
# File 'app/models/spree/price_rule.rb', line 41

def contextual?
  self.class.contextual?
end