Closed seand7565 closed 2 years ago
Looking into this a bit further - we get our states from Carmen. We get the Carmen::Country
and then the subregions of that country. For Italy, we actually want to get the subregions subregions. Carmen::Country.coded("IT").subregions.map(&:subregions)
There are only a handful of countries with nested subregions, and only nested up to twice - there are no countries with subregions that have subregions that have subregions. My guess is that for each of these countries, we actually need the nested subregions instead of the top level subregions. I will attempt to do some research for each of these to verify that theory. If it's true, then this should be a simple fix.
Countries with nested subregions:
<#Carmen::Country name="Albania">
<#Carmen::Country name="Azerbaijan">
<#Carmen::Country name="Bosnia and Herzegovina">
<#Carmen::Country name="Bangladesh">
<#Carmen::Country name="Belgium">
<#Carmen::Country name="Burkina Faso">
<#Carmen::Country name="Canada">
<#Carmen::Country name="Cabo Verde">
<#Carmen::Country name="Czechia">
<#Carmen::Country name="Spain">
<#Carmen::Country name="France">
<#Carmen::Country name="United Kingdom">
<#Carmen::Country name="Guinea">
<#Carmen::Country name="Equatorial Guinea">
<#Carmen::Country name="Greece">
<#Carmen::Country name="Guinea-Bissau">
<#Carmen::Country name="Indonesia">
<#Carmen::Country name="Ireland">
<#Carmen::Country name="Italy">
<#Carmen::Country name="Saint Kitts and Nevis">
<#Carmen::Country name="Sri Lanka">
<#Carmen::Country name="Morocco">
<#Carmen::Country name="Marshall Islands">
<#Carmen::Country name="Maldives">
<#Carmen::Country name="Malawi">
<#Carmen::Country name="Mexico">
<#Carmen::Country name="Nepal">
<#Carmen::Country name="Philippines">
<#Carmen::Country name="Serbia">
<#Carmen::Country name="Uganda">
Canada doesn't have nested subregions afaict (and as a Canadian I can confirm that the top-level subregions are our provinces.)
[11] pry(main)> canada.subregions.map &:subregions
=> [[], [], [], [], [], [], [], [], [], [], [], [], []]
Maybe I'm not on master, but I got an ever so slightly different result:
[12] pry(main)> Carmen::Country.all.select {|c| c.subregions.flat_map(&:subregions).any? }
=> [<#Carmen::Country name="Albania">,
<#Carmen::Country name="Azerbaijan">,
<#Carmen::Country name="Bosnia and Herzegovina">,
<#Carmen::Country name="Bangladesh">,
<#Carmen::Country name="Belgium">,
<#Carmen::Country name="Burkina Faso">,
<#Carmen::Country name="Cape Verde">,
<#Carmen::Country name="Czech Republic">,
<#Carmen::Country name="Spain">,
<#Carmen::Country name="France">,
<#Carmen::Country name="Guinea">,
<#Carmen::Country name="Equatorial Guinea">,
<#Carmen::Country name="Greece">,
<#Carmen::Country name="Guinea-Bissau">,
<#Carmen::Country name="Indonesia">,
<#Carmen::Country name="Ireland">,
<#Carmen::Country name="Italy">,
<#Carmen::Country name="Saint Kitts and Nevis">,
<#Carmen::Country name="Sri Lanka">,
<#Carmen::Country name="Morocco">,
<#Carmen::Country name="Marshall Islands">,
<#Carmen::Country name="Maldives">,
<#Carmen::Country name="Malawi">,
<#Carmen::Country name="Nepal">,
<#Carmen::Country name="New Zealand">,
<#Carmen::Country name="Philippines">,
<#Carmen::Country name="Serbia">,
<#Carmen::Country name="Uganda">]
Hmm, this is the result I get when listing subregions for subregions for Canada:
2.6.1 :102 > Carmen::Country.coded("CA").subregions.map(&:subregions)
=> [[], [], [], [], [], [], [], [], [], [], [<#Carmen::Region name="Bas-Saint-Laurent" type="region">, <#Carmen::Region name="Saguenay–Lac-Saint-Jean" type="region">, <#Carmen::Region name="Capitale-Nationale" type="region">, <#Carmen::Region name="Mauricie" type="region">, <#Carmen::Region name="Estrie" type="region">, <#Carmen::Region name="Montréal" type="region">, <#Carmen::Region name="Outaouais" type="region">, <#Carmen::Region name="Abitibi-Témiscamingue" type="region">, <#Carmen::Region name="Côte-Nord" type="region">, <#Carmen::Region name="Nord-du-Québec" type="region">, <#Carmen::Region name="Gaspésie–Îles-de-la-Madeleine" type="region">, <#Carmen::Region name="Chaudière-Appalaches" type="region">, <#Carmen::Region name="Laval" type="region">, <#Carmen::Region name="Lanaudière" type="region">, <#Carmen::Region name="Laurentides" type="region">, <#Carmen::Region name="Montérégie" type="region">, <#Carmen::Region name="Centre-du-Québec" type="region">], [], []]
I wonder why it's different - I'm on a relatively new installation of Solidus (~ a few months ago) on cutting edge
I'm not, I grabbed an older app to test, I'm sure that's it. Those are administrative regions of Quebec and not necessary for addresses afaik. There are also a lot of region types in Carmen:
parish, emirate, province, dependency, district, county, city, state, territory, rayon, municipality, autonomous republic, canton, entity, division, region, governorate, department, special municipality, federal district, oblast, prefecture, commune, economic prefecture, capital district, autonomous region, special administrative region, geographical region, autonomous community, autonomous city, administration, metropolitan department, metropolitan region, overseas territorial collectivity, overseas region/department, council area, unitary authority (wales), district council area, unitary authority (england), london borough, metropolitan district, two-tier county, included for completeness, country, city corporation, special zone, self-governed part, administrative region, autonomous sector, city with county rights, capital city, geographical unit, special district, special region, autonomous province, union territory, autonomous municipality, island group, island, special city, capital metropolitan city, metropolitan cities, republican city, popularates, economic region, quarter, autonomous territorial unit, territorial unit, chains (of islands), local council, administrative atoll, federal territories, capital territory, arctic region, zone, development region, special island authority, regional council, unitary authority, indigenous region, constitutional province, area, republic, administrative territory, autonomous district, town council, geographical entity, municipalities, borough, island council, outlying area, apo, federal dependency
From my googling session earlier, it looks like the subregions of subregions are correct for mailing addresses for at least some of the countries listed - UK, Albania, France, Spain and Italy. But it sounds like we'll need to specify which countries use nested subregions and which use the top level subregions.
After a long period of time looking into this, I've come to the conclusion that addresses are awful and we should toss out the whole system and come up with something better on a global scale.
Failing that, we should probably just start by singling out a handful of countries on the list that are more likely to be shipped to (I'd imagine France, Italy, Ireland, Spain, and Mexico are hotspots) and put a check in to ensure we're using the right subdivision for those countries.
I'll try to get a PR open for at least Italy soon. I'll also see if there's a process we can implement for people to "upgrade" to these new states - so that people upgrading to the new Solidus version have a chance to use the new list of states for the countries we're updating.
Closing, it has been addressed in #3722. cc @gsmendoza
Italian addresses utilize provinces for states, however Solidus default states for Italy use regions. This leads to addresses in Solidus like:
Strada Comunale Piana, 1, 65129 Pescara, Abruzzo, Italy
which is incorrect and might lead to some lost packages or third party validation issues - the correct address is:Strada Comunale Piana, 1, 65129 Pescara PE, Italy
where PE is the abbreviation for the province of Pescara.We should swap to using provinces for states, as this is the standard for Italian addresses.