4

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

1 Answer 1

6

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

3
  • This doesn't seem to work.Error is Uncaught exception 'Mage_Eav_Exception' with message 'Invalid attribute name: customer_group_id.
    – blakcaps
    Commented Mar 5, 2013 at 12:01
  • change the condition to 'customer_group_id=group_id' the first "parameter" must be the name from the joined table. The error is raise because of this: blog.fabian-blechschmidt.de/articles/… Commented Mar 5, 2013 at 12:15
  • I made a few corrections to the code above. Commented Mar 5, 2013 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.