How to join the below two collection for customer & Customer Address I want to use on grid

$entityType = Mage::getModel('eav/entity_type')->loadByCode('customer_address');
$customerAddressCollection = Mage::getModel('eav/entity_attribute')->getCollection()->setEntityTypeFilter($entityType);


$entityType = Mage::getModel('eav/entity_type')->loadByCode('customer');
$customerCollection = Mage::getModel('eav/entity_attribute')->getCollection()->setEntityTypeFilter($entityType);

You can check the code below.

It allow you to change the entities you want to merge and give you a $customCollection to set to your grid.

    // init
    $entitiesToMerge = array('customer_address', 'customer');
    $entitiesData = array();

    // get the entities objects and data
    if (!empty($entitiesToMerge)) {
        foreach($entitiesToMerge as $entityCode) {
            $entity = Mage::getModel('eav/entity_type')->loadByCode($entityCode);
            $entitiesData['id'][]         = $entity->getId();
            $entitiesData['additional'][] = $entity->getAdditionalAttributeTable();
    // sanitize
    $entitiesData['id']          = array_unique($entitiesData['id']);
    $entitiesData['additional']  = array_unique($entitiesData['additional']);

    // create custom collection
    $customCollection = Mage::getModel('eav/entity_attribute')->getCollection();

    //filter the collection with the entity_types
    $customCollection->addFieldToFilter('main_table.entity_type_id', array('in' => $entitiesData['id']));
    // join additionnal attributes data table
    if (!empty($entitiesData['additional'])) {
        foreach($entitiesData['additional'] as $idx => $additionalTable) {
                array('additional_table_' . $idx => $additionalTable),
                'additional_table_' . $idx . '.attribute_id = main_table.attribute_id'
    // check the request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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