Passing a locale to the getAdministrativeAreasListByCountryCode() method (class Store) #3088
Unanswered
ianreidlangevin
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone!
I may be missing something, but I believe it would be helpful to have a parameter for a locale in the getAdministrativeAreasListByCountryCode() method (for example, to pass the currentSite.locale).
Reference :
commerce/src/models/Store.php
Lines 185 to 197 in 652e6ce
The getList([$countryCode]) method would accept a locale code string as a second parameter on line 193. The return value would be the list of subdivisions for the related country from commerceguys/addressing in the wanted locale (ex: Colombie Britannique for the 'fr' locale rather than British Colombia).
I did it with a simple loop in Twig by merging in an object each country code and its subdivisions, but it seems to replicate the getAdministrativeAreasListByCountryCode() method that is doing pretty much the same.
{% set countries = craft.commerce.store.getStore().getCountries() %}
{% set countriesWithLocalizedStates = {} %}
{% for item in countries %}
{% set states = craft.app.getAddresses().getSubdivisionRepository.getList([item], currentSite.locale) %}
{% set countriesWithLocalizedStates = countriesWithLocalizedStates|merge({ (item) : states}) %}
{% endfor %}
Sorry for bad English, I'm not a native English speaker.
Thanks a lot and have a nice day!
Beta Was this translation helpful? Give feedback.
All reactions