Question

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

Thank you.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top