Class: Spree::Variant::PriceSelector
- Inherits:
-
Object
- Object
- Spree::Variant::PriceSelector
- Defined in:
- app/models/spree/variant/price_selector.rb
Overview
This class is responsible for selecting a price for a variant given certain pricing options. A variant can have multiple or even dynamic prices. The ‘price_for_options` method determines which price applies under the given circumstances.
Instance Attribute Summary collapse
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Class Method Summary collapse
-
.pricing_options_class ⇒ Object
The pricing options represent “given circumstances” for a price: The currency we need and the country that the price applies to.
Instance Method Summary collapse
-
#initialize(variant) ⇒ PriceSelector
constructor
A new instance of PriceSelector.
-
#price_for_options(price_options) ⇒ Spree::Price?
The variant’s Spree::Price record, given a set of pricing options.
Constructor Details
#initialize(variant) ⇒ PriceSelector
Returns a new instance of PriceSelector.
21 22 23 |
# File 'app/models/spree/variant/price_selector.rb', line 21 def initialize(variant) @variant = variant end |
Instance Attribute Details
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
19 20 21 |
# File 'app/models/spree/variant/price_selector.rb', line 19 def variant @variant end |
Class Method Details
.pricing_options_class ⇒ Object
The pricing options represent “given circumstances” for a price: The currency we need and the country that the price applies to. Every price selector is designed to work with a particular set of pricing options embodied in it’s pricing options class.
15 16 17 |
# File 'app/models/spree/variant/price_selector.rb', line 15 def self. Spree::Variant::PricingOptions end |
Instance Method Details
#price_for_options(price_options) ⇒ Spree::Price?
The variant’s Spree::Price record, given a set of pricing options
28 29 30 31 32 33 34 |
# File 'app/models/spree/variant/price_selector.rb', line 28 def () sorted_prices_for(variant).detect do |price| (price.country_iso == .desired_attributes[:country_iso] || price.country_iso.nil? ) && price.currency == .desired_attributes[:currency] end end |