Question

How do I add company and group name to this collection

$collection = Mage::getResourceModel('customer/customer_collection')               
               ->addAttributeToSelect('*')             
               ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
               ->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_fax', 'customer_address/fax', 'default_billing', null, 'left')
               ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
               ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')               

               ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
               ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
               ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
               ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
               ->joinAttribute('shipping_fax', 'customer_address/fax', 'default_shipping', null, 'left')
               ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
               ->joinAttribute('shipping_country_code', 'customer_address/country_id', 'default_shipping', null, 'left')
               ->joinAttribute('taxvat', 'customer/taxvat', 'entity_id', null, 'left');  
Was it helpful?

Solution

Company is a customer_address attribute, therefore you have to decide wether it should be from the shipping or billing address or join both like the rest.

And group name, like this:

$collection->joinTable('customer/customer_group', 'customer_group_id=group_id', array('customer_group_code'), null, 'left');

Didn't tested it ;-)

It is important to set as the condition the column of the joined table as first name.

I wrote a blog article about it: http://blog.fabian-blechschmidt.de/articles/Joining-a-flat-table-on-EAV.html

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top