我如何阅读客户国家?我尝试这样做:Magento阅读客户国家
$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email');
但我不能找到客户国家,州等属性
我如何阅读客户国家?我尝试这样做:Magento阅读客户国家
$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email');
但我不能找到客户国家,州等属性
装入客户地址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();
试试这个,
<?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();
有了您的帮助,我这样做:
$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'];
}