2012-10-15 28 views
1

我期待將所有客戶地址屬性加入到完整客戶集合中。將所有地址詳細信息加入到客戶集合中

$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*'); 
$collection->joinField('is_active', 'customer/address', 'is_active','parent_id=entity_id'); 

給了我致命的錯誤:

Mage_Core_Exception: Can't retrieve entity config: customer/address in /app/Mage.php on line 563 

由於我使用的是企業,我們必須添加客戶地址屬性的能力,所以採用加盟的具體地址屬性的方法是不一樣令人滿意在這段代碼片段中:

$collection->addNameToSelect() 
    ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left') 
    ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left') 
    ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left') 
    ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left') 
    ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left') 

任何想法?謝謝。

回答

1

我設法找到一種方式,雖然它不是超級優雅,但它適用於我。基本上,我們可以遍歷所有的地址屬性,並以這種方式添加我們的joinAttribute()

$addressCollection = Mage::getModel('customer/address')->getCollection()->addAttributeToSelect('*'); 
$addressCollection->getSelect()->limit(1); 
$address = $addressCollection->getFirstItem(); 
foreach ($address->getAttributes() as $attribute) { 
    if (is_null($attribute->getAttributeID()) || is_null($attribute->getFrontendLabel()) || ($attribute->getFrontendLabel() == '')) { 
     continue; 
    } 
    $collection->joinAttribute($attribute->getName(), 'customer_address/' . $attribute->getName(), 'default_billing', null, 'left'); 
} 

請注意,我們忽略沒有標籤的屬性,因爲我只想要「真實」的客戶地址信息。

相關問題