Sha256: 4304805a4684516874dab6083629dcd630a742078d2da3ba01a69ca8bff570fd

Contents?: true

Size: 760 Bytes

Versions: 26

Compression:

Stored size: 760 Bytes

Contents

module Spree
  class State < Spree::Base
    belongs_to :country, class_name: 'Spree::Country'
    has_many :addresses, dependent: :nullify

    validates :country, :name, presence: true

    def self.find_all_by_name_or_abbr(name_or_abbr)
      where('name = ? OR abbr = ?', name_or_abbr, name_or_abbr)
    end

    # table of { country.id => [ state.id , state.name ] }, arrays sorted by name
    # blank is added elsewhere, if needed
    def self.states_group_by_country_id
      state_info = Hash.new { |h, k| h[k] = [] }
      order(:name).each { |state|
        state_info[state.country_id.to_s].push [state.id, state.name]
      }
      state_info
    end

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

    def to_s
      name
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
solidus_core-2.2.2 app/models/spree/state.rb
solidus_core-2.1.1 app/models/spree/state.rb
solidus_core-2.0.3 app/models/spree/state.rb
solidus_core-1.4.2 app/models/spree/state.rb
solidus_core-1.3.2 app/models/spree/state.rb
solidus_core-2.0.2 app/models/spree/state.rb
solidus_core-1.4.1 app/models/spree/state.rb
solidus_core-2.2.1 app/models/spree/state.rb
solidus_core-2.2.0 app/models/spree/state.rb
solidus_core-2.2.0.rc1 app/models/spree/state.rb
solidus_core-2.2.0.beta1 app/models/spree/state.rb
solidus_core-2.1.0 app/models/spree/state.rb
solidus_core-2.1.0.rc1 app/models/spree/state.rb
solidus_core-2.0.1 app/models/spree/state.rb
solidus_core-2.1.0.beta1 app/models/spree/state.rb
solidus_core-2.0.0 app/models/spree/state.rb
solidus_core-1.4.0 app/models/spree/state.rb
solidus_core-2.0.0.rc1 app/models/spree/state.rb
solidus_core-1.4.0.rc1 app/models/spree/state.rb
solidus_core-2.0.0.beta1 app/models/spree/state.rb