2

customer_entity_varcharテーブルから注文グリッドに「accountno」フィールドを追加しようとしています。これを実現するために、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_idaccountno`=122' 122 is the attribute_id of

selectクエリを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
      }
4

0 に答える 0