我试图按国家/地区名称查找国家/地区代码.所以,例如,我有"荷兰",我需要得到"NL"
我知道有找到名称格式代码的方法:
$country_name = Mage::app()->getLocale()->getCountryTranslation($country_code)
Run Code Online (Sandbox Code Playgroud)
但我需要反过来.
那么Magento有什么方法可以解决它吗?
从另一个问题来看,这只能通过循环遍历国家集合来完成
$countryId = '';
$countryCollection = Mage::getModel('directory/country')->getCollection();
foreach ($countryCollection as $country) {
if ($countryName == $country->getName()) {
$countryId = $country->getCountryId();
break;
}
}
echo $countryId;
Run Code Online (Sandbox Code Playgroud)
由于数据如何存储在XML中,因此无法按名称进行过滤或加载.
这适合我
$list = Mage::app()->getLocale()->getCountryTranslationList(); $list=array_flip($list);
echo $list['United States'];
| 归档时间: |
|
| 查看次数: |
11742 次 |
| 最近记录: |