I have created a custom customer attribute, let's call it my_custom_attribute.
I need to extend an order collection to include this custom customer attribute for each order.
I have solved this by joining the customer_entity_varchar (since the attribute is of the varchar type) table into the product collection, to get the customer's ID from that:
// First I figure out the internal attribute ID of the custom attribute $attributeId = Mage::getModel('customer/customer')->getResource()->getAttribute('my_custom_attribute')->getId(); $collection->getSelect() ->joinLeft( array('customers' => Mage::getSingleton('core/resource')->getTableName('customer_entity_varchar')), 'customers.entity_id = `main_table`.customer_id AND customers.attribute_id = ' . $attributeId, array('my_custom_attribute' => 'customers.value') )
This works for me, but I feel like it's not a very elegant solution? Is there another more elegant way that I've overlooked?