10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/services/spree/seeds/countries.rb', line 10
def call
ApplicationRecord.transaction do
if Rails::VERSION::MAJOR >= 6
new_countries = Carmen::Country.all.map do |country|
next if EXCLUDED_COUNTRIES.include?(country.alpha_2_code)
Hash[
'name': country.name,
'iso3': country.alpha_3_code,
'iso': country.alpha_2_code,
'iso_name': country.name.upcase,
'numcode': country.numeric_code,
]
end.compact.uniq
Spree::Country.insert_all(new_countries)
else
Carmen::Country.all.each do |country|
next if EXCLUDED_COUNTRIES.include?(country.alpha_2_code)
Spree::Country.where(
name: country.name,
iso3: country.alpha_3_code,
iso: country.alpha_2_code,
iso_name: country.name.upcase,
numcode: country.numeric_code
).first_or_create!
end
end
Spree::Country.where(iso: Spree::Address::NO_ZIPCODE_ISO_CODES).update_all(zipcode_required: false)
Spree::Country.where(iso: Spree::Address::STATES_REQUIRED).update_all(states_required: true)
end
end
|