我正在尝试获取国家名称“美国”(或首字母“美国”/“美国”)。我在以下方面尝试了很多变体:
echo Mage::getSingleton('customer/session')->getCustomer()->getCountry();
$countryName = Mage::getModel('directory/country')->load(Mage::getSingleton('customer/session')->getCustomer()->getCountry())->getName();
error_log("countryName = $countryName");
第一个电话“似乎”有效,因为我得到了 6 回(美国)。但在那之后,我无法找到如何将其映射到正确的名称或蛞蝓。
我看过一些帖子,程序员得到了所有国家名称和 ID 的列表,但我不想遍历所有组合来查找名称。
蒂亚!
编辑:根据clockworkgeeks的建议,我尝试过:
$customer = Mage::getSingleton('customer/session')->getCustomer();
error_log(print_r($customer, true));
$countryCode = $customer->getDefaultBillingAddress()->getCountry();
但是,第 3 行调用 getCountry() 失败。也许 getDefaultBillingAddress() 没有返回对象。错误信息:
PHP Fatal error: Call to a member function getCountry() on a non-object in ...
想法?$customer 对象正在正确返回,尽管CLASS是一个 MYCLIENT_Customer_Model_Customer 对象......也许它没有扩展正确的父对象以使其访问 getCountry?
编辑:(解决方案):作为答案添加。