Sha256: b5f88becd05c4d571fd7a1f84ec8fc28036ec389394b0baf4234e862ff736093

Contents?: true

Size: 737 Bytes

Versions: 28

Compression:

Stored size: 737 Bytes

Contents

# frozen_string_literal: true

module Spree
  module DefaultPrice
    extend ActiveSupport::Concern

    included do
      has_one :default_price,
        -> { with_discarded.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

28 entries across 28 versions & 1 rubygems

Version Path
solidus_core-3.0.8 app/models/concerns/spree/default_price.rb
solidus_core-3.0.7 app/models/concerns/spree/default_price.rb
solidus_core-2.11.17 app/models/concerns/spree/default_price.rb
solidus_core-2.11.16 app/models/concerns/spree/default_price.rb
solidus_core-3.0.6 app/models/concerns/spree/default_price.rb
solidus_core-2.11.15 app/models/concerns/spree/default_price.rb
solidus_core-2.11.14 app/models/concerns/spree/default_price.rb
solidus_core-3.0.5 app/models/concerns/spree/default_price.rb
solidus_core-2.11.13 app/models/concerns/spree/default_price.rb
solidus_core-3.0.4 app/models/concerns/spree/default_price.rb
solidus_core-2.11.12 app/models/concerns/spree/default_price.rb
solidus_core-3.0.3 app/models/concerns/spree/default_price.rb
solidus_core-2.11.11 app/models/concerns/spree/default_price.rb
solidus_core-3.0.2 app/models/concerns/spree/default_price.rb
solidus_core-2.11.10 app/models/concerns/spree/default_price.rb
solidus_core-3.0.1 app/models/concerns/spree/default_price.rb
solidus_core-3.0.0 app/models/concerns/spree/default_price.rb
solidus_core-2.11.9 app/models/concerns/spree/default_price.rb
solidus_core-2.11.8 app/models/concerns/spree/default_price.rb
solidus_core-2.11.7 app/models/concerns/spree/default_price.rb