Sha256: 212d598f4f40bce64ed93ad1b3099563d135e993d0813520330c0e0986169792

Contents?: true

Size: 1.11 KB

Versions: 32

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

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

    self.whitelisted_ransackable_attributes = %w[name]

    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 self.available(restrict_to_zone: Spree::Config[:checkout_zone])
      checkout_zone = Zone.find_by(name: restrict_to_zone)

      return checkout_zone.country_list if checkout_zone.try(:kind) == 'country'

      all
    end

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

    def to_s
      name
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

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