我如何閱讀客戶國家?我嘗試這樣做: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'];
}