Sha256: 349ec8725b59ff2d50db3616c4014ec1ba5c4351fe0d5b9326b8c67c537a2186

Contents?: true

Size: 818 Bytes

Versions: 25

Compression:

Stored size: 818 Bytes

Contents

module Spree
  class Country < Spree::Base
    has_many :states, -> { order(:name) }, dependent: :destroy
    has_many :addresses, dependent: :nullify
    has_many :prices, class_name: "Spree::Price", foreign_key: "country_iso", primary_key: "iso"

    validates :name, :iso_name, presence: true

    def self.default
      if Spree::Config.default_country_id
        Spree::Deprecation.warn("Setting your default country via its ID is deprecated. Please set your default country via the `default_country_iso` setting.", caller)
        find_by(id: Spree::Config.default_country_id) || find_by!(iso: Spree::Config.default_country_iso)
      else
        find_by!(iso: Spree::Config.default_country_iso)
      end
    end

    def <=>(other)
      name <=> other.name
    end

    def to_s
      name
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
solidus_core-2.5.2 app/models/spree/country.rb
solidus_core-2.5.1 app/models/spree/country.rb
solidus_core-2.5.0 app/models/spree/country.rb
solidus_core-2.5.0.rc1 app/models/spree/country.rb
solidus_core-2.5.0.beta2 app/models/spree/country.rb
solidus_core-2.5.0.beta1 app/models/spree/country.rb
solidus_core-2.4.2 app/models/spree/country.rb
solidus_core-2.3.1 app/models/spree/country.rb
solidus_core-2.4.1 app/models/spree/country.rb
solidus_core-2.2.2 app/models/spree/country.rb
solidus_core-2.1.1 app/models/spree/country.rb
solidus_core-2.4.0 app/models/spree/country.rb
solidus_core-2.4.0.rc1 app/models/spree/country.rb
solidus_core-2.4.0.beta1 app/models/spree/country.rb
solidus_core-2.3.0 app/models/spree/country.rb
solidus_core-2.3.0.rc3 app/models/spree/country.rb
solidus_core-2.3.0.rc2 app/models/spree/country.rb
solidus_core-2.3.0.rc1 app/models/spree/country.rb
solidus_core-2.3.0.beta1 app/models/spree/country.rb
solidus_core-2.2.1 app/models/spree/country.rb