Module: Spree::DefaultPrice
- Extended by:
- ActiveSupport::Concern
- Included in:
- Variant
- Defined in:
- app/models/concerns/spree/default_price.rb
Instance Method Summary collapse
-
#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
#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.
39 40 41 |
# File 'app/models/concerns/spree/default_price.rb', line 39 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
21 22 23 24 |
# File 'app/models/concerns/spree/default_price.rb', line 21 def default_price_or_build default_price || prices.build(self.class.default_price_attributes) end |
#has_default_price? ⇒ Boolean
43 44 45 |
# File 'app/models/concerns/spree/default_price.rb', line 43 def has_default_price? default_price.present? && !default_price.discarded? end |