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>
Returns ‘#prices` prioritized for being considered as default price.
-
#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
20 21 22 |
# File 'app/models/concerns/spree/default_price.rb', line 20 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. Discarded prices are also considered.
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.
46 47 48 49 50 51 52 |
# File 'app/models/concerns/spree/default_price.rb', line 46 def default_price prioritized_default( prices_meeting_criteria_to_be_default( (prices + prices.with_discarded).uniq ) ) end |
#default_price_or_build ⇒ Spree::Price?
Returns #default_price or builds it from Variant.default_price_attributes
28 29 30 31 |
# File 'app/models/concerns/spree/default_price.rb', line 28 def default_price_or_build default_price || prices.build(self.class.default_price_attributes) end |
#has_default_price? ⇒ Boolean
54 55 56 |
# File 'app/models/concerns/spree/default_price.rb', line 54 def has_default_price? default_price.present? && !default_price.discarded? end |