Magento - 为客户选择邮政编码和地址

发布于 2024-10-08 14:30:23 字数 45 浏览 2 评论 0原文

如何在前端模块中检索一个或多个客户的地址和邮政编码?

谢谢。

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

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心 2024-10-15 14:30:23

使用以下代码:- (在 @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();
?>

我不太确定区域/州值。但我想你可以从这里开始。

希望有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文