Sha256: 1186ab8ff9399ea71609872e095fc4faf06f6545d58fd85627f06bef9feff1f1

Contents?: true

Size: 641 Bytes

Versions: 3

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true

def create_states(subregions, country)
  subregions.each do |subregion|
    Spree::State.where(abbr: subregion.code, country:).first_or_create!(
      name: subregion.name
    )
  end
end

ActiveRecord::Base.transaction do
  Spree::Country.all.find_each do |country|
    carmen_country = Carmen::Country.coded(country.iso)
    next unless carmen_country.subregions?

    if Spree::Config[:countries_that_use_nested_subregions].include? country.iso
      create_states(carmen_country.subregions.flat_map(&:subregions), country)
    else
      create_states(carmen_country.subregions, country)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_core-4.4.2 db/default/spree/states.rb
solidus_core-4.4.1 db/default/spree/states.rb
solidus_core-4.4.0 db/default/spree/states.rb