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

#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


39
40
41
# File 'app/models/concerns/spree/default_price.rb', line 39

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


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