Sha256: f8141e20e858ecd0d1972236665ccf1c05017f0f9db7599c82c5555b8fee5d4a

Contents?: true

Size: 942 Bytes

Versions: 74

Compression:

Stored size: 942 Bytes

Contents

module Spree
  module DefaultPrice
    extend ActiveSupport::Concern

    included do
      has_one :default_price,
              -> { where currency: Spree::Config[:currency] },
              class_name: 'Spree::Price',
              dependent: :destroy

      delegate :display_price, :display_amount, :price, :currency, :price=,
               :price_including_vat_for, :currency=, to: :find_or_build_default_price

      after_save :save_default_price

      def default_price
        Spree::Price.unscoped { super }
      end

      def has_default_price?
        !default_price.nil?
      end

      def find_or_build_default_price
        default_price || build_default_price
      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

74 entries across 74 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/concerns/spree/default_price.rb
spree_core-4.1.15 app/models/concerns/spree/default_price.rb
spree_core-4.1.14 app/models/concerns/spree/default_price.rb
spree_core-4.0.8 app/models/concerns/spree/default_price.rb
spree_core-3.7.14.1 app/models/concerns/spree/default_price.rb
spree_core-4.1.13.1 app/models/concerns/spree/default_price.rb
spree_core-4.0.7.1 app/models/concerns/spree/default_price.rb
spree_core-4.0.7 app/models/concerns/spree/default_price.rb
spree_core-3.7.14 app/models/concerns/spree/default_price.rb
spree_core-4.1.13 app/models/concerns/spree/default_price.rb
spree_core-4.0.6 app/models/concerns/spree/default_price.rb
spree_core-3.7.13 app/models/concerns/spree/default_price.rb
spree_core-4.0.5 app/models/concerns/spree/default_price.rb
spree_core-4.1.12 app/models/concerns/spree/default_price.rb
spree_core-3.7.12 app/models/concerns/spree/default_price.rb
spree_core-4.0.4 app/models/concerns/spree/default_price.rb
spree_core-3.7.11 app/models/concerns/spree/default_price.rb
spree_core-4.1.11 app/models/concerns/spree/default_price.rb
spree_core-4.1.10 app/models/concerns/spree/default_price.rb
spree_core-4.1.9 app/models/concerns/spree/default_price.rb