Sha256: eef66dc9b69512baee37049d7af60555218153b41856227bf64ba0412628a582

Contents?: true

Size: 735 Bytes

Versions: 14

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

module Spree
  module DefaultPrice
    extend ActiveSupport::Concern

    included do
      has_one :default_price,
        -> { with_deleted.currently_valid.with_default_attributes },
        class_name: 'Spree::Price',
        inverse_of: :variant,
        dependent: :destroy,
        autosave: true
    end

    def find_or_build_default_price
      default_price || build_default_price(Spree::Config.default_pricing_options.desired_attributes)
    end

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

    def has_default_price?
      default_price.present? && !default_price.discarded?
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
solidus_core-2.10.5 app/models/concerns/spree/default_price.rb
solidus_core-2.10.3 app/models/concerns/spree/default_price.rb
solidus_core-2.10.2 app/models/concerns/spree/default_price.rb
solidus_core-2.9.6 app/models/concerns/spree/default_price.rb
solidus_core-2.10.1 app/models/concerns/spree/default_price.rb
solidus_core-2.9.5 app/models/concerns/spree/default_price.rb
solidus_core-2.10.0 app/models/concerns/spree/default_price.rb
solidus_core-2.9.4 app/models/concerns/spree/default_price.rb
solidus_core-2.9.3 app/models/concerns/spree/default_price.rb
solidus_core-2.9.2 app/models/concerns/spree/default_price.rb
solidus_core-2.10.0.beta1 app/models/concerns/spree/default_price.rb
solidus_core-2.9.1 app/models/concerns/spree/default_price.rb
solidus_core-2.9.0 app/models/concerns/spree/default_price.rb
solidus_core-2.9.0.rc.1 app/models/concerns/spree/default_price.rb