Ravish
Ravish

Reputation: 2421

Fatal Error: Magento Add Column to Admin Customer Grid

I wanted to add a column to Admin Customer Grid is_onHold (there is column in customer_entity table named is_onHold, tinyint(1) {want to store boolean value}).

I tried Fabrizio d solution from : Magento - Add column to customer grid, but, it's giving fatal error when trying to filter result based on the column added.

I added following code in _prepareColumns():

$this->addColumn('is_onHold', array(
            'header'    => Mage::helper('customer')->__('On Hold?'),
            'width'     => '150',
            'index'     => 'is_onHold',
            'type'      => 'options',
            'options'   => array(
              1 => 'Yes',
              0 => 'No',
          )
        ));

and following code in _prepareCollection():

->addAttributeToSelect('is_onHold')

It works perfectly, and column is added to the grid, but, when I try to filter the record based on newly added column, I get error Mage EAV Error

when I checked the corresponding error report, it says:

a:5:{i:0;s:34:"Invalid attribute name: is_onHold.";i:1;s:5418:"#0 E:\wamp\www\magePrj\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(1166): Mage::exception('Mage_Eav', 'Invalid attribu...')
1 E:\wamp\www\magePrj\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(1255): Mage_Eav_Model_Entity_Collection_Abstract->_addAttributeJoin('is_onHold', 'inner')
2 E:\wamp\www\magePrj\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(292): Mage_Eav_Model_Entity_Collection_Abstract->_getAttributeConditionSql('is_onHold', Array, 'inner')
3 E:\wamp\www\magePrj\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php(312): Mage_Eav_Model_Entity_Collection_Abstract->addAttributeToFilter('is_onHold', Array)
4 E:\wamp\www\magePrj\app\code\core\Mage\Adminhtml\Block\Widget\Grid.php(449): Mage_Eav_Model_Entity_Collection_Abstract->addFieldToFilter('is_onHold', Array)

Is this because I am trying to use type options for a boolean column? I am not sure what I am doing wrong...

Upvotes: 3

Views: 3799

Answers (1)

Ravish
Ravish

Reputation: 2421

I've found the solution to the problem I was facing. After banging my head against the wall for hours.

Actually, there was nothing wrong with using any data type for column. So, the problem was not in the table.

I checked all related files. And, finally, found where the problem was. Actually, I was right till:

$this->addColumn('is_onHold', array(
        'header'  => Mage::helper('customer')->__('On Hold?'),
        'width'   => '120',
        'index'   => 'is_onHold',
        'type'    => 'options',
        'options' => array('1' => 'Yes', '0' => 'No')
));

and

->addAttributeToSelect('is_onHold')

But, I think when you use above method, you need to make one additional change to Mage_Customer_Model_Entity_Customer->_getDefaultAttributes() and your columns there...

like I did :

return array(
            'entity_type_id',
            'attribute_set_id',
            'created_at',
            'updated_at',
            'increment_id',
            'store_id',
            'website_id',
            'is_onHold',
            'hold_till'
        );

Last 2 in the array are columns added by me...

Hope this will help someone...

Upvotes: 6

Related Questions