문제

How can I retrieve the address and zip code of one or more customers in frontend module?

Thank you.

도움이 되었습니까?

해결책

Use the following code:- (Edited after some nice codes by @clockworkgeek)

<?php
$primaryAddress = Mage::getSingleton('customer/session')->getCustomer()
                  ->getPrimaryShippingAddress();

$arrCountryList = Mage::getModel('directory/country_api')->items();
$countryName = '';
foreach($arrCountryList as $_eachCountryList) {
    if ($primaryAddress['country_id'] == $_eachCountryList['country_id']) {
        $countryName = $_eachCountryList['name'];
        break;
    }
}

$countryName = Mage::getModel('directory/country')
               ->loadByCode($primaryAddress->getCountryId())
               ->getName();

echo '<br/>Street Address: '.$primaryAddress->getStreet();
echo '<br/>City: '.$primaryAddress->getCity();
echo '<br/>State/Region: '.$primaryAddress->getRegion();
echo '<br/>Country Code: '.$primaryAddress->getCountryId();
echo '<br/>Country Name: '.$countryName;
echo '<br/>Zip Code: '.$primaryAddress->getPostcode();
?>

I'm not quite sure about the region / state value. But I suppose you can start off from here.

Hope it helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top