我正在尝试添加'accountno'字段来从customer_entity_varchar表中订购网格。为了实现这一点,我改变了Grid.php中的_prepareCollection()方法,如下所示:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$customerEntityVarchar = Mage::getSingleton('core/resource')->getTableName('customer_entity_varchar');
$collection->getSelect()->join(array(
'customer_entity_varchar_table'=>$customerEntityVarchar),
'`main_table`.`customer_id`=`customer_entity_varchar_table`.`entity_id`
AND `customer_entity_varchar_table`.`attribute_id`=122',
array('accountno' => 'value'));
print_r($collection->getSelect()->__toString());
$this->setCollection($collection);
return parent::_prepareCollection();
}
在attribute_id
中=122' 122 is the attribute_id of
accountno`
当我print_r选择查询并在phpmyadmin中执行它时,它会得到准确的结果,但是当我尝试在_prepareColumns()方法中将列添加到网格时,它会将该字段显示为空白。 我的_prepareColumns方法如下所示:
protected function _prepareColumns()
{
$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
));
$this->addColumnAfter('accountno', array(
'header' => Mage::helper('sales')->__('Account No'),
'index' => 'accountno',
), 'real_order_id');
//rest of the code here
}