I have tried to find country code by country name. So, for example, I have "Netherlands", I need to get "NL"
I know there is method to find name form code:
$country_name = Mage::app()->getLocale()->getCountryTranslation($country_code)
But I need vice versa.
So is there any methods in Magento to resolve it?
From the other question, this can only be done by looping through the country collection
$countryId = '';
$countryCollection = Mage::getModel('directory/country')->getCollection();
foreach ($countryCollection as $country) {
if ($countryName == $country->getName()) {
$countryId = $country->getCountryId();
break;
}
}
echo $countryId;
Because of how the data is stored in the XML there is no way to filter or load by name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With