Sha256: d0755002a1a9af1bbce1739d56714037a0aa8c307c92c7898e40708c03080f89

Contents?: true

Size: 1.03 KB

Versions: 18

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Spree
  class UserAddress < Spree::Base
    belongs_to :user, class_name: UserClassHandle.new, foreign_key: "user_id", optional: true
    belongs_to :address, class_name: "Spree::Address", optional: true

    validates_uniqueness_of :address_id, scope: :user_id
    validates_uniqueness_of :user_id, conditions: -> { active.default_shipping }, message: :default_address_exists, if: :default?

    scope :with_address_values, ->(address_attributes) do
      joins(:address).merge(
        Spree::Address.with_values(address_attributes)
      )
    end

    scope :all_historical, -> { unscope(where: :archived) }
    scope :default_shipping, -> { where(default: true) }
    scope :default_billing, -> { where(default_billing: true) }
    scope :active, -> { where(archived: false) }

    scope :default, -> do
      Spree::Deprecation.warn "This scope is deprecated. Please start using ::default_shipping."
      default_shipping
    end

    default_scope -> { order([default: :desc, updated_at: :desc]) }
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
solidus_core-2.11.17 app/models/spree/user_address.rb
solidus_core-2.11.16 app/models/spree/user_address.rb
solidus_core-2.11.15 app/models/spree/user_address.rb
solidus_core-2.11.14 app/models/spree/user_address.rb
solidus_core-2.11.13 app/models/spree/user_address.rb
solidus_core-2.11.12 app/models/spree/user_address.rb
solidus_core-2.11.11 app/models/spree/user_address.rb
solidus_core-2.11.10 app/models/spree/user_address.rb
solidus_core-2.11.9 app/models/spree/user_address.rb
solidus_core-2.11.8 app/models/spree/user_address.rb
solidus_core-2.11.7 app/models/spree/user_address.rb
solidus_core-2.11.6 app/models/spree/user_address.rb
solidus_core-2.11.5 app/models/spree/user_address.rb
solidus_core-2.11.4 app/models/spree/user_address.rb
solidus_core-2.11.3 app/models/spree/user_address.rb
solidus_core-2.11.2 app/models/spree/user_address.rb
solidus_core-2.11.1 app/models/spree/user_address.rb
solidus_core-2.11.0 app/models/spree/user_address.rb