从Magento中提取国家/地区名称(或缩写)

mr-*_*-sk 1 php country magento

我正在尝试将国家名称命名为"United States"(或缩写为"USA"/"US").我在下面尝试了很多变化:

echo Mage::getSingleton('customer/session')->getCustomer()->getCountry();
$countryName = Mage::getModel('directory/country')->load(Mage::getSingleton('customer/session')->getCustomer()->getCountry())->getName();
error_log("countryName = $countryName");
Run Code Online (Sandbox Code Playgroud)

第一个电话"似乎"起作用,因为我得到了6回(美国).但在那之后,我无法找到如何将其映射到正确的名称或slug.

我已经看过程序员获取所有国家名称和id的列表的帖子,但我不想迭代所有组合来查找名称.

TIA!

编辑:根据clockworkgeeks的建议,我试过:

$customer = Mage::getSingleton('customer/session')->getCustomer();
error_log(print_r($customer, true));
$countryCode = $customer->getDefaultBillingAddress()->getCountry();
Run Code Online (Sandbox Code Playgroud)

但是,第3行无法调用getCountry().也许getDefaultBillingAddress()不会返回对象.错误信息:

PHP Fatal error:  Call to a member function getCountry() on a non-object in ...
Run Code Online (Sandbox Code Playgroud)

思考?$ customer对象正确返回,虽然CLASS是MYCLIENT_Customer_Model_Customer对象...也许它不会扩展正确的父对象以使其访问getCountry?

编辑:(解决方案):添加为答案.

clo*_*eek 14

通常情况下,像国家这样的信息根本不存储在客户实体中,我不确定为什么你得到"6".

$customer = Mage::getSingleton('customer/session')->getCustomer();
$countryCode = $customer->getDefaultBillingAddress()->getCountry();
// $countryCode looks like "US"
$country = Mage::getModel('directory/country')->loadByCode($countryCode);
echo $country->getName(); // looks like "United States"
Run Code Online (Sandbox Code Playgroud)