Magento发票网格过滤器\u条件\u回调不工作

Magento发票网格过滤器\u条件\u回调不工作,magento,filter,grid,Magento,Filter,Grid,我使用观察者向发票网格添加了一个自定义列。 问题是我无法按新列进行排序或筛选 我添加了一个过滤条件回调,但没有调用该函数 这是我的Observer.php class DB_CustomGrid_Model_Adminhtml_Observer { public function onBlockHtmlBefore(Varien_Event_Observer $observer) { $block = $observer->getBlock();

我使用观察者向发票网格添加了一个自定义列。 问题是我无法按新列进行排序或筛选

我添加了一个过滤条件回调,但没有调用该函数

这是我的Observer.php

class DB_CustomGrid_Model_Adminhtml_Observer
{
    public function onBlockHtmlBefore(Varien_Event_Observer $observer)
    {
        $block = $observer->getBlock();

        $payment_methods = array();
        $readConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
        $query = 'SELECT method FROM '.Mage::getSingleton('core/resource')->getTableName('sales/order_payment').' GROUP BY method';
        $methods = $readConnection->fetchAll($query);
        foreach($methods as $payment) {
            if($payment["method"] !== 'free') {
                $payment_methods[$payment["method"]] = Mage::getStoreConfig('payment/'.$payment["method"].'/title');
            }
        }

        switch ($block->getType()) {
            case 'adminhtml/sales_invoice_grid':
                $block->addColumnAfter('state', array(
                    'header' => Mage::helper('sales')->__('Payment Method'),
                    'index' => 'method',
                    'type'  => 'options',
                    'width' => '70px',
                    'options' => $payment_methods,
                    'filter' => false,
                    'filter_condition_callback' => array($this, '_myCustomFilter'),
                ), 'method');
            break;
        }
    }

    public function beforeCollectionLoad(Varien_Event_Observer $observer)
    {
        $collection = $observer->getOrderInvoiceGridCollection();
        $collection->join(array('payment'=>'sales/order_payment'),'main_table.order_id=parent_id',array('method'));
    }

    protected function _myCustomFilter($collection, $column)
    {
        exit;
        if (!$value = $column->getFilter()->getValue()) {
            return $collection;
        }

        $collection->getCollection()->getSelect()->where("sales_order_payment.method like ?", "%$value%");
        return $collection;
    }
}
我加了一个出口;要检查函数是否被调用。

请尝试以下操作:

将新的受保护函数添加到observer类:

protected function _callProtectedMethod($object, $methodName) {
    $reflection = new ReflectionClass($object);
    $method = $reflection->getMethod($methodName);
    $method->setAccessible(true);
    return $method->invoke($object);
}

然后调用
$block->sortcolumnsbylder()
,新函数
$this->\u调用protectedmethod($block,'u prepareCollection')
直接位于
$block->addColumnAfter()之后

尝试重写adminhtml/sales\u invoice\u网格,在网格中添加列和过滤器。我认为'filter\u condition\u callback'=>数组中的$this($this,'.\u myCustomFilter')表示观察者不是网格。我不想重写核心文件。这就是我使用观察者方法的原因。我可以访问那里的网格对象吗?但是我认为不管第一个参数是什么,都应该调用该函数?因此,请尝试传递$block而不是$this。我的CustomFilter中没有$collection。这是可行的,但为什么需要这样做呢?OP的逻辑有什么问题?这是否被标记为解决方案??为什么。。。试图理解这里的错误。。。因为在Magento 1.9.2中。这在1.9.3之后运行良好。不再尝试此解决方案,现在请参见
方法\u prepareCollection不存在