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

        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?

  • Also was watching for solution. Found the following: magento.stackexchange.com/questions/19296/… – Amberta Jan 30 '15 at 13:41
  • Thanks, that looks interesting, but in my case I need to be able to dynamically update the custom attribute, and this change should also be reflected in the order collection. – Louis B. Jan 30 '15 at 13:58

If it works it is ok. You have the customer_id in the order and you can join into the varchar table. I think it is fine.

Your Answer

