2013-02-19 21 views
0

我创建了一个用于在magento后端列出客户的新模块。添加额外的字段值在magento中的客户模块网格中未显示

一切都会好的,但这里有一些问题。

我为客户注册比率创建了一些额外的字段。此字段值现在不在网格中显示。

这是我的grid.php代码:

<?php 
class Pfay_Test_Block_Adminhtml_Test_Grid extends Mage_Adminhtml_Block_Widget_Grid 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->setId('customerGrid'); 
     $this->setDefaultSort('entity_id'); 
     $this->setDefaultDir('DESC'); 
     $this->setSaveParametersInSession(true); 
    } 
    protected function _prepareCollection() 
    { 
     $collection = Mage::getResourceModel('customer/customer_collection') 
      ->addNameToSelect() 
      ->addAttributeToSelect('email') 
      ->addAttributeToSelect('usertype') 
      ->addAttributeToSelect('created_at') 
      ->addAttributeToSelect('group_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('entity_id', array(
      'header' => Mage::helper('customer')->__('ID'), 
      'width'  => '50px', 
      'index'  => 'entity_id', 
      'type' => 'number', 
     )); 
     $this->addColumn('firstname', array(
      'header' => Mage::helper('customer')->__('First Name'), 
      'index'  => 'firstname' 
     )); 
     $this->addColumn('lastname', array(
      'header' => Mage::helper('customer')->__('Last Name'), 
      'index'  => 'lastname' 
     )); 
     $this->addColumn('email', array(
      'header' => Mage::helper('customer')->__('Email'), 
      'width'  => '150', 
      'index'  => 'email' 
     )); 
     $this->addColumn('usertype', array(
      'header' => Mage::helper('customer')->__('User Type'), 
      'width'  => '150', 
      'index'  => 'usertype' 
     )); 
     $this->addColumn('action', 
      array(
       'header' => Mage::helper('customer')->__('Action'), 
       'width'  => '100', 
       'type'  => 'action', 
       'getter' => 'getId', 
       'actions' => array(
        array(
         'caption' => Mage::helper('customer')->__('Edit'), 
         'url'  => array('base'=> '*/*/edit'), 
         'field'  => 'id' 
        ) 
       ), 
       'filter' => false, 
       'sortable' => false, 
       'index'  => 'stores', 
       'is_system' => true, 
     )); 

     $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV')); 
     $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML')); 
     return parent::_prepareColumns(); 
    } 
    public function getRowUrl($row) 
    { 
     return $this->getUrl('*/*/edit', array('id' => $row->getId())); 
    } 
} 

的名字,姓氏,电子邮件显示正常,但对于用户类型的列不显示否值。

我该怎么做?

有没有可能解决这个问题?

+0

您必须使用$ this-> addColumn() – 2013-02-19 13:55:36

+0

将新添加的列添加到网格中。他已经完成了此操作。 – seanbreeden 2013-02-19 14:15:18

回答

0
protected function _prepareColumns() 
{ 
    $this->addColumn('entity_id', array(
     'header' => Mage::helper('customer')->__('ID'), 
     'width'  => '50px', 
     'index'  => 'entity_id', 
     'type' => 'number', 
    )); 
    $this->addColumn('firstname', array(
     'header' => Mage::helper('customer')->__('First Name'), 
     'index'  => 'firstname' 
    )); 
    $this->addColumn('lastname', array(
     'header' => Mage::helper('customer')->__('Last Name'), 
     'index'  => 'lastname' 
    )); 
    $this->addColumn('email', array(
     'header' => Mage::helper('customer')->__('Email'), 
     'width'  => '150', 
     'index'  => 'email' 
    )); 
    $this->addColumn('usertype', array(
     'header' => Mage::helper('customer')->__('User Type'), 
     'width'  => '150', 
     'index'  => 'usertype' 
    )); 
    $this->addColumn('action', 
     array(
      'header' => Mage::helper('customer')->__('Action'), 
      'width'  => '100', 
      'type'  => 'action', 
      'getter' => 'getId', 
      'actions' => array(
       array(
        'caption' => Mage::helper('customer')->__('Edit'), 
        'url'  => array('base'=> '*/*/edit'), 
        'field'  => 'id' 
       ) 
      ), 
      'filter' => false, 
      'sortable' => false, 
      'index'  => 'stores', 
      'is_system' => true, 
    )); 

    $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV')); 
    $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML')); 

    // Changed lines here 
    parent::_prepareColumns(); 
    return $this; 
    // end of changed lines 

} 
+0

现在不用dsplaying'usertype' – Kichu 2013-02-22 05:20:10

+0

你有什么解决方法吗? – Kichu 2013-02-22 05:23:38

+0

好的,然后把它改回'return parent :: _ prepareColumns();'。看到我上面编辑的答案 – seanbreeden 2013-02-22 15:16:43

相关问题