2

我正在尝试将“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 ofaccountno`

当我 print_r 选择查询并在 phpmyadmin 中执行它时,它会返回准确的结果,但是当我尝试在 _prepareColumns() 方法中将 Column 添加到网格时,它显示该字段为空白。我的 _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
      }
4

0 回答 0