Magento读客户国家

时间:2014-11-21 07:16:21

标签: magento

如何阅读客户所在国家/地区?我试过这个:

$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email');

但是我找不到客户所在国家/地区,州等。

3 个答案:

答案 0 :(得分:1)

试试这个,

<?php

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();


$customerId = 136;

$customer = Mage::getModel('customer/customer')->load($customerId); 

$customerAddress = array();
#loop to create the array
foreach ($customer->getAddresses() as $address)
{
    $customerAddress = $address->toArray();
}

/* echo '<pre/>';
print_r($customerAddress );
 */
$country_id = $customerAddress['country_id'];

$countryModel = Mage::getModel('directory/country')->loadByCode($country_id);
echo $countryName = $countryModel->getName();

答案 1 :(得分:0)

在第一行代码中加载您的客户地址ID,您最终会获得以下详细信息:

    $address = Mage::getModel('customer/address')->load($customerAddressId);
    $fullname = $customer->getName();
    $firstname = $customer->getFirstname();
    $lastname = $customer->getLastname();
    $email = $customer->getEmail();
    $taxvat = $customer->getTaxvat();
    $tele = $customer->getTelephone();
    $telephone = $address->getTelephone();
    $street = $address->getStreet();
    $City = $address->getCity();
    $region = $address->getRegion();
    $postcode = $address->getPostcode();

答案 2 :(得分:0)

在你的帮助下,我这样做了:

        $collection = Mage::getModel('customer/customer')->getCollection()
            ->addAttributeToSelect('entity_id')
            ->addAttributeToSelect('firstname')
            ->addAttributeToSelect('lastname')
            ->addAttributeToSelect('email');

        foreach ($collection as $item) {
            $row = $item->getData();

                $customerId = $row['entity_id'];
                $customer = Mage::getModel('customer/customer')->load($customerId);

                foreach ($customer->getAddresses() as $address)
                {
                    $customerAddress = $address->toArray();
                    break;
                }

                $country = Mage::app()->getLocale()->getCountryTranslation( $customerAddress['country_id']);
                $state = $customerAddress['region'];

        }