Module: Spree::DefaultPrice

Extended by:
ActiveSupport::Concern
Included in:
Variant
Defined in:
app/models/concerns/spree/default_price.rb

Instance Method Summary collapse

Instance Method Details

#currently_valid_pricesActiveRecord::Relation<Spree::Price>

Deprecated.

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_priceSpree::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.

See Also:

  • Variant.default_price_attributes


48
49
50
# File 'app/models/concerns/spree/default_price.rb', line 48

def default_price
  price_selector.price_for_options(Spree::Config.default_pricing_options)
end

#default_price_or_buildSpree::Price?

Returns #default_price or builds it from Variant.default_price_attributes

See Also:

  • 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