Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

join collection to get the customer name (for admin grid)

Tags:

magento

I have a table for my custom module with following columns:

---------------
| custom_table|
---------------
| id
| seller_id
| buyer_id
| ...
---------------

seller_id -> customer_enity [entity_id]
buyer_id -> customer_entity [entity_id]

Now i would like to show the seller name and buyer name in admin grid layout. I couldn’t figure out how to retrieve the seller name and buyer name from the customer entities. But i know how to retrieve their emails as:

protected function _prepareCollection()
{
  $collection = Mage::getModel('custommodule/custommodule')->getCollection();  
  $collection->getSelect()
        ->join( array('ce1' => 'customer_entity'), 'ce1.entity_id=main_table.seller_id', array('seller_email' => 'email'))
        ->join( array('ce2' => 'customer_entity'), 'ce2.entity_id=main_table.buyer_id', array('buyer_email' => 'email'));
  #echo $collection->getSelect()->__toString();
  $this->setCollection($collection);
  return parent::_prepareCollection();
}

This above code works fine. But i want to display their names instead of email. Can any body help me to modify this collection?

Any help is very much appreciated. Thanks

like image 551
user292125 Avatar asked Jun 23 '10 05:06

user292125


1 Answers

You need to join with customer_entity_varchar table where the name is store,
and the attribute_id = 5, 5 because it is the id of the attribute name in the table eav_attribute where all attributes are store
hope it help you

like image 127
Castro Roy Avatar answered Oct 13 '22 06:10

Castro Roy