【问题标题】:Fatal Error: Magento Add Column to Admin Customer Grid致命错误:Magento 将列添加到管理客户网格
【发布时间】:2011-11-14 09:25:56
【问题描述】:

我想在管理客户网格 is_onHold 中添加一列(customer_entity 表中有名为 is_onHold 的列,tinyint(1) {想要存储布尔值}) .

我尝试了来自 Magento - Add column to customer gridFabrizio d 解决方案,但是,在尝试根据添加的列过滤结果时出现致命错误。

我在 _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',
          )
        ));

以及_prepareCollection()中的以下代码:

->addAttributeToSelect('is_onHold')

效果很好,列已添加到网格中,但是,当我尝试根据新添加的列过滤记录时,出现错误

当我检查相应的错误报告时,它说:

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)

这是因为我试图为布尔列使用类型选项吗? 我不确定我做错了什么......

【问题讨论】:

  • 我也尝试更改列类型 ENUM,仍然是同样的错误...我 100% 确定我没有拼错,因为,我已经检查了两次,三次,我不知道多少次了……

标签: magento magento-1.5


【解决方案1】:

我找到了解决我所面临问题的方法。 在把我的头撞在墙上几个小时之后。

实际上,对列使用任何数据类型都没有错。所以,问题不在表中。

我检查了所有相关文件。最后,找到了问题所在。 实际上,我是对的,直到:

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

->addAttributeToSelect('is_onHold')

但是,我认为当您使用上述方法时,您需要对 Mage_Customer_Model_Entity_Customer->_getDefaultAttributes() 和您的列进行额外的更改...

像我一样:

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

数组中的最后 2 个是我添加的列...

希望这会对某人有所帮助...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多