在Magento客户网格中添加新列customer_id无索引值

在Magento客户网格中添加新列customer_id无索引值,magento,Magento,在Magento客户网格中添加新列customer\u id,无索引值 在我的Magento客户网格中添加新列customer\u id时出现问题,导致没有索引值。该列为空 这是我的密码: <?php class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid { public function __construct() { parent::__const

在Magento客户网格中添加新列
customer\u id
,无索引值

在我的Magento客户网格中添加新列
customer\u id
时出现问题,导致没有索引值。该列为空

这是我的密码:

<?php
   class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
   public function __construct()
    {
     parent::__construct();
    $this->setId('customerGrid');
    $this->setUseAjax(true);
    $this->setDefaultSort('entity_id');
    $this->setSaveParametersInSession(true);
    }   

 protected function _prepareCollection()
   {
    $collection = Mage::getResourceModel('customer/customer_collection')        
        ->addNameToSelect()             
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')  
        ->addAttributeToSelect('customer_id')           
        ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
        ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
        ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
    $this->setCollection($collection);

    return parent::_prepareCollection();
}

 protected function _prepareColumns()
    {      
         $this->addColumn('customer_id', array(
        'header'    => Mage::helper('sales')->__('Customer ID'),
        'width'     => '50px',
        'index'     => 'customer_id',
        'type'  => 'number',
    ));
   /*more columns*/
   return parent::_prepareColumns();
  }  }

您没有提到是否覆盖了
Mage\u Adminhtml\u Block\u Customer\u网格
,因为您从
core/Mage
中放入了代码

但是如果您要覆盖它,那么我建议您不要覆盖
\u prepareCollection()
,而是覆盖方法
setCollection()
,如下所示:

public function setCollection($collection) {
    $collection->addAttributeToSelect('customer_id'); //although this may not add that column for you.
// you need to join the collection with your table in order to do that
    $this->_collection = $collection;
}
然后将柱添加到轴网中,如下所示:

protected function _prepareColumns() {
    $this->addColumnAfter('customer_id', array(
        'header' => Mage::helper('customer')->__('Customer ID'),
        'type' => 'text',
        'index' => 'customer_id'
    ), 'entity_id');
    return parent::_prepareColumns();
}

您可以添加网格的屏幕截图吗?为什么要将
customer\u id
添加到另一个表中?