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

私は Enterprise を使用しているため、顧客の住所属性を追加する機能があるため、次のコード スニペットのように特定の住所属性を結合する方法を使用しても満足のいくものではありません。

$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')

何か案は?ありがとうございました。

4

1 に答える 1

2

とてもエレガントではありませんが、なんとか方法を見つけることができましたが、私にとってはうまくいきます。基本的に、すべてのアドレス属性を循環して、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');
}

「実際の」顧客住所情報のみが必要なため、ラベルのない属性は無視していることに注意してください。

于 2012-10-19T18:46:46.930 に答える