Sha256: ef2c11f302e6d7befbb6023c2fa8c02f0007fd0c6b8bdc38cdb662b7c773da85
Contents?: true
Size: 992 Bytes
Versions: 7
Compression:
Stored size: 992 Bytes
Contents
module Spree module DefaultPrice extend ActiveSupport::Concern included do has_one :default_price, -> { where currency: Spree::Config[:currency], is_default: true }, class_name: 'Spree::Price', inverse_of: :variant, dependent: :destroy, autosave: true def find_or_build_default_price default_price || build_default_price end delegate :display_price, :display_amount, :price, :price=, :currency, :currency=, to: :find_or_build_default_price after_save :save_default_price def default_price Spree::Price.unscoped { super } end def has_default_price? !self.default_price.nil? end private def default_price_changed? default_price && (default_price.changed? || default_price.new_record?) end def save_default_price default_price.save if default_price_changed? end end end end
Version data entries
7 entries across 7 versions & 1 rubygems