2
如何檢索前端模塊中一個或多個客戶的地址和郵政編碼?Magento - 爲客戶選擇郵政編碼和地址
謝謝。 (由@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();
?>
我不太清楚有關地區/國家價值 - :
不工作! :( – Bizboss 2010-12-20 10:34:50
@Bizboss - 我想你已經插入了賬單的「default_billing」和Shipping的「default_shipping」,否則沒有任何Magento的默認代碼可以工作。 – 2010-12-20 10:48:36
地址是一個對象,所以不應該被視爲一個數組,使用getters()) - > getName();' – clockworkgeek 2010-12-20 12:03:05