Class: Spree::PriceRule
- Inherits:
-
Object
- Object
- Spree::PriceRule
- Defined in:
- app/models/spree/price_rule.rb
Direct Known Subclasses
Spree::PriceRules::ChannelRule, Spree::PriceRules::CustomerGroupRule, Spree::PriceRules::MarketRule, Spree::PriceRules::UserRule, Spree::PriceRules::VolumeRule, Spree::PriceRules::ZoneRule
Class Method Summary collapse
-
.contextual? ⇒ Boolean
Whether this rule narrows by something about the purchase rather than about the buyer.
-
.description ⇒ String
Returns the description of the price rule.
-
.human_name ⇒ String
Returns the human name of the price rule.
-
.superseded? ⇒ Boolean
Whether a better mechanism has replaced this rule kind.
Instance Method Summary collapse
-
#applicable?(context) ⇒ Boolean
Returns true if the price rule is applicable to the context.
-
#contextual? ⇒ Boolean
Instance-side reader, so rules can be classified per row (
price_rules.select(&:contextual?)).
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).
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
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
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).
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
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.
41 42 43 |
# File 'app/models/spree/price_rule.rb', line 41 def contextual? self.class.contextual? end |