Sha256: 3d8a2c8725706dcfa09b786cd89fa2a1d6da0b1b8572bfbb17384b3fec32fcda

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

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.states_required_by_country_id
      Spree::Deprecation.warn "Spree::Country.states_required_by_country_id is deprecated and will be removed from future releases, Implement it yourself.", caller
      states_required = Hash.new(true)
      all.each { |country| states_required[country.id.to_s] = country.states_required }
      states_required
    end

    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

12 entries across 12 versions & 1 rubygems

Version Path
solidus_core-2.0.3 app/models/spree/country.rb
solidus_core-1.4.2 app/models/spree/country.rb
solidus_core-2.0.2 app/models/spree/country.rb
solidus_core-1.4.1 app/models/spree/country.rb
solidus_core-2.0.1 app/models/spree/country.rb
solidus_core-2.1.0.beta1 app/models/spree/country.rb
solidus_core-2.0.0 app/models/spree/country.rb
solidus_core-1.4.0 app/models/spree/country.rb
solidus_core-2.0.0.rc1 app/models/spree/country.rb
solidus_core-1.4.0.rc1 app/models/spree/country.rb
solidus_core-2.0.0.beta1 app/models/spree/country.rb
solidus_core-1.4.0.beta1 app/models/spree/country.rb