Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Update Carmen Data Import
Matthew Kennedy8b4079e2f5cd
diff --git a/core/app/models/spree/address.rb b/core/app/models/spree/address.rbindex 370876d32a..c98b55e7a1 100644--- a/core/app/models/spree/address.rb+++ b/core/app/models/spree/address.rb@@ -10,10 +10,10 @@ module Spree'TO', 'TV', 'UG', 'AE', 'VU', 'YE', 'ZW'].freeze- # The Information for this matches that used by PayPal, Stripe, and Shopify.+ # The required states listed below match those used by PayPal and Shopify.STATES_REQUIRED = [- 'AU', 'AE', 'BR', 'CA', 'CN', 'ES', 'HK', 'IE', 'IN', 'IT', 'MY', 'MX', 'NZ', 'PT', 'RO',- 'TH', 'US', 'ZA'+ 'AU', 'AE', 'BR', 'CA', 'CN', 'ES', 'HK', 'IE', 'IN',+ 'IT', 'MY', 'MX', 'NZ', 'PT', 'RO', 'TH', 'US', 'ZA'].freeze# we're not freezing this on purpose so developers can extend and managediff --git a/core/db/default/spree/countries.rb b/core/db/default/spree/countries.rbindex e6cfe559e0..bf6a76c901 100644--- a/core/db/default/spree/countries.rb+++ b/core/db/default/spree/countries.rb@@ -1,6 +1,11 @@require 'carmen'+EXCLUDED_COUNTRIES = ['AQ', 'AX', 'GS', 'UM', 'HM', 'IO', 'EH', 'BV', 'TF'].freeze+Carmen::Country.all.each do |country|+ # Skip the creation of some territories, uninhabited islands and the Antarctic.+ next if EXCLUDED_COUNTRIES.include?(country.alpha_2_code)+Spree::Country.where(name: country.name,iso3: country.alpha_3_code,diff --git a/core/db/default/spree/states.rb b/core/db/default/spree/states.rbindex 20814ce365..3b2d9fc4cd 100644--- a/core/db/default/spree/states.rb+++ b/core/db/default/spree/states.rb@@ -1,22 +1,49 @@+# frozen_string_literal: true++EXCLUDED_US_STATES = ['UM', 'AS', 'MP', 'VI', 'PR', 'GU'].freeze+EXCLUDED_CN_STATES = ['HK', 'MO', 'TW'].freeze++def state_level(country, subregion)+ country.states.where(+ name: subregion.name,+ abbr: subregion.code+ ).first_or_create+end++def province_level(country, subregion)+ subregion.subregions.each do |province|+ country.states.where(+ name: province.name,+ abbr: province.code+ ).first_or_create+ end+end+Spree::Country.where(states_required: true).each do |country|carmen_country = Carmen::Country.named(country.name)next unless carmen_countrycarmen_country.subregions.each do |subregion|- if subregion.subregions?- subregion.subregions.each do |province|- country.states.where(- name: province.name,- abbr: province.code,- country_id: country.id- ).first_or_create- end+ if carmen_country.alpha_2_code == 'US'+ # Produces 50 states, one postal district (Washington DC)+ # and 3 APO's as you would expect to see on any good U.S. states list.+ next if EXCLUDED_US_STATES.include?(subregion.code)++ state_level(country, subregion)+ elsif carmen_country.alpha_2_code == 'CA' || carmen_country.alpha_2_code == 'MX'+ # Force Canada and Mexico to use state-level data import from Carmen Gem+ # else we pull in a subset of provinces that are not common at checkout.+ state_level(country, subregion)+ elsif carmen_country.alpha_2_code == 'CN'+ # Removes 3 "States" from that list that are also listed as Countries,+ # Hong Kong, Taiwan and Macao+ next if EXCLUDED_CN_STATES.include?(subregion.code)++ state_level(country, subregion)+ elsif subregion.subregions?+ province_level(country, subregion)else- country.states.where(- name: subregion.name,- abbr: subregion.code,- country_id: country.id- ).first_or_create+ state_level(country, subregion)endendenddiff --git a/core/db/default/spree/zones.rb b/core/db/default/spree/zones.rbindex 4df53e2de6..e32f14a9c8 100644--- a/core/db/default/spree/zones.rb+++ b/core/db/default/spree/zones.rb@@ -16,7 +16,7 @@ endmiddle_east.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!end-%w(AF AM AZ BH BD BT BN KH CN CX CC IO GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NP+%w(AF AM AZ BH BD BT BN KH CN CX CC GE HK IN ID IR IQ IL JP JO KZ KW KG LA LB MO MY MV MN MM NPKP OM PK PS PH QA SA SG KR LK SY TW TJ TH TR TM AE UZ VN YE).each do |name|asia.zone_members.where(zoneable: Spree::Country.find_by!(iso: name)).first_or_create!end