Module: Spree::DefaultPrice
- Extended by:
- ActiveSupport::Concern
- Included in:
- Variant
- Defined in:
- app/models/concerns/spree/default_price.rb
Instance Method Summary collapse
- #currently_valid_prices ⇒ ActiveRecord::Relation<Spree::Price> deprecated Deprecated.
-
#default_price ⇒ Spree::Price?
Select from #prices the one to be considered as the default.
-
#default_price_or_build ⇒ Spree::Price?
Returns #default_price or builds it from Variant.default_price_attributes.
- #has_default_price? ⇒ Boolean
Instance Method Details
#currently_valid_prices ⇒ ActiveRecord::Relation<Spree::Price>
Returns ‘#prices` prioritized for being considered as default price
21 22 23 |
# File 'app/models/concerns/spree/default_price.rb', line 21 def currently_valid_prices prices.currently_valid end |
#default_price ⇒ Spree::Price?
Select from #prices the one to be considered as the default
This method works with the in-memory association, so non-persisted prices are taken into account.
A price is a candidate to be considered as the default when it meets Variant.default_price_attributes criteria. When more than one candidate is found, non-persisted records take preference. When more than one persisted candidate exists, the one most recently updated is taken or, in case of race condition, the one with higher id.
48 49 50 |
# File 'app/models/concerns/spree/default_price.rb', line 48 def default_price price_selector.(Spree::Config.) end |
#default_price_or_build ⇒ Spree::Price?
Returns #default_price or builds it from Variant.default_price_attributes
30 31 32 33 |
# File 'app/models/concerns/spree/default_price.rb', line 30 def default_price_or_build default_price || prices.build(self.class.default_price_attributes) end |
#has_default_price? ⇒ Boolean
52 53 54 |
# File 'app/models/concerns/spree/default_price.rb', line 52 def has_default_price? default_price.present? && !default_price.discarded? end |