【问题标题】:Magento - Select zip code and address for customer(s)Magento - 为客户选择邮政编码和地址
【发布时间】:2023-03-15 00:28:01
【问题描述】:

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

谢谢。

【问题讨论】:

    标签: magento magento-1.4


    【解决方案1】:

    使用以下代码:- (在 @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']; 休息; } } 罢工>
    $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 - 我想你已经插入了 Billing 的“default_billing”和 Shipping 的“default_shipping”。否则 Magento 的默认代码都不起作用。
    • 地址是一个对象,所以不应该真正被视为一个数组,而是使用getter。对于您可能正在寻找的国家/地区,$countryName = Mage::getModel('directory/country') -&gt;loadByCode($primaryAddress-&gt;getCountryId())-&gt;getName();
    • @clockworkgeek - 非常感谢您提及正确的代码。更新了答案。
    • 谢谢大家,我使用了 Mage::getResourceModel('customer/customer_collection') 因为我想从数据库中选择很多客户,但是您的帖子很有帮助;)非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 2014-01-26
    • 1970-01-01
    相关资源
    最近更新 更多