where magento stores country full name

2019-05-05 18:59发布

I have spent hours searching to find where magento stores full county name. We can get a full list of countries using this code:

$_countries = Mage::getResourceModel('directory/country_collection')
    ->loadData()
    ->toOptionArray(false);

This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table

directory_county

But this table don't have full county name! So where is it stored? and how is it retrieved using that call?

Thanks in advance.

4条回答
放荡不羁爱自由
2楼-- · 2019-05-05 19:36

Use the Zend_Local translation.

<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>

Use the column 'iso2_code' from the table 'directory_country' for your $code.

查看更多
女痞
3楼-- · 2019-05-05 19:41

Ok so to compensate for my wrong answer. Here is how this works:

  1. /lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag <territory>

  2. The xml is cached using the Zend_Cache_Core class.

  3. /lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class to load from the cache.

Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.

查看更多
神经病院院长
4楼-- · 2019-05-05 19:44

Full country names are not stored in database. Magento uses inbuilt Zend functionality.

Check file: lib/Zend/Locale/Data/Translation.php for full list.

查看更多
走好不送
5楼-- · 2019-05-05 19:52

Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.

By the toOptionArray method it invokes the Zend_Locale class to get the translated value.

Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);, which gets to Mage_Core_Model_Locale and then to Zend_Locale.

It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent() line# 962, 963

Magento caches the names, so if you make any change to XML files, make sure to clean your cache folder to get what you seek.

查看更多
登录 后发表回答