2010-06-23 62 views
5

我有一个表,我的自定义模块与下列:加入收藏获取客户名称(管理网格)

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

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

现在我想显示在管理网格布局,卖方名称和买方名称。 我无法弄清楚如何从客户实体中检索卖家姓名和买家姓名。 但我知道如何获取他们的电子邮件为:

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

这上面的代码工作正常。但我想显示他们的名字而不是电子邮件。 任何机构可以帮助我修改这个集合吗?

任何帮助,非常感谢。 感谢

回答

3

您需要customer_entity_varchar表加入其中,名称是商店,
和attribute_id = 5,5,因为它是属性名称的表格中eav_attribute的ID,所有属性都是商店
希望帮助你

1

您可以使用此代码来获得顾客的名字和姓氏

$this->_infoCollection = Mage::getModel('custommodule/custommodule')->getCollection() 
    ->addFieldToFilter('ce2.attribute_id', array('eq' => array(5))) 
    ->addFieldToFilter('ce3.attribute_id', array('eq' => array(7))); 

    $this->_infoCollection->getSelect() 
    ->join(array('ce1' => 'customer_entity'), 'ce1.entity_id=main_table.customer_id', array('customer_email' => 'email')) 
    ->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=ce1.entity_id', array('customer_first_name' => 'value')) 
    ->join(array('ce3' => 'customer_entity_varchar'), 'ce3.entity_id=ce1.entity_id', array('customer_last_name' => 'value'));