2011-08-08 3 views
1

"미국"(또는 "미국"/ "미국")의 국가 이름을 얻으려고합니다. 나는 다음에 변화의 무리를 시도했다 :Magento에서 국가 이름 (또는 이니셜)을 추출합니다.

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의 목록을 가져 오는 게시물을 보았습니다. 그러나 이름을 찾기 위해 모든 조합을 반복하고 싶지는 않습니다.

TIA!

편집 : 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 ... 

생각 하시겠습니까? 클래스은 MYCLIENT_Customer_Model_Customer 객체입니다. $ getCountry에 액세스 할 수 있도록 적절한 부모를 확장하지 않습니다.

수정 : (솔루션) : 답변으로 추가되었습니다. 당신이 "6"을 얻을 왜 국가와 같은 http://blog.chapagain.com.np/magento-get-country-and-region-collection/

답변

-1

그래서 저는 수행하여이 문제를 해결 : 도움을

customer_model_object = Mage::getSingleton('customer/customer'); 
$session = Mage::getSingleton('customer/session'); 
$country_name = $customer_model_object->load($session->getId())->getResource()->getAttribute('country')->getFrontend()->getValue($customer_model_object); 

감사합니다. 당신은 clockworkgeek이었습니다, 이것은 adminhtml에서 고객 엔티티에 추가 된 속성입니다. 나는이 모든 재즈를 통해 국가 슬러그 (예 : "미국")에 액세스해야했습니다.

3

아마이 도움이 :에서

$countryName = 
    Mage::getModel('directory/country')->load($countryCode)->getName(); 

.

$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" 
14

일반적으로 정보가 모든 고객 엔티티에 저장되지 않습니다, 나는 확실 해요 :

+0

어쩌면 이것이 우리가 구축했거나 확장 한 EAV 시스템 때문일 수도 있습니다. 다시 말하지만, 필자는 글자 그대로이 프로젝트에 포함되었습니다. 전반적인 Magento 지식은 희박합니다. –

+0

이것이 실패하면 getCountry() 호출이 작동하지 않으므로 getDefaultBillingAddress()가 객체를 반환하지 않을 수 있습니다. 내 영업에서 구현. –

+0

귀하의 사이트가 개별 주소 개체를 사용하지 않도록 변경되었거나 조사중인 고객에게 주소가 없다는 의미입니다. 데이터베이스에서'directory_country' 테이블을 볼 때 숫자 필드가 없으므로 "6"값을 사용하는 방법을 알 수 없습니다. 아마도 당신이 복사 할 수있는 방법으로 그 값을 사용하고있는 로컬 확장 (MYCLIENT 폴더 확인)이있을 것입니다. – clockworkgeek

관련 문제