使用filter_condition_callback过滤计数列Magento Customer Admin网格

时间:2013-11-05 17:37:55

标签: php magento zend-framework magento-1.7

我已修改../app/code/local/Mage/Adminhtml/Block/Customer/Grid.php中的magento客户管理网格以包含总订单,但需要应用过滤器,我一直在使用filter_condition_callback但无法使其正常工作。有什么建议吗?

修改后的收藏:

    $collection->getSelect()->joinLeft(array('sales_flat_order'), 'sales_flat_order.customer_id=e.entity_id', array('order_total' => 'COUNT(customer_id)'));
    $collection->groupByAttribute('entity_id')

订购总栏目:

        $this->addColumn('order_total', array(
        'header' => Mage::helper('customer')->__('Total Orders'),
        'type' => 'text',
        'index' => 'order_total',
        //'filter' => true,
        'sortable' => false,
        'filter_condition_callback' => array($this, '_orderTotalFilter'),
    ));

OrderTotalFilter回调:

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

        $this->getCollection()->getSelect()->where('condition = ?', "$value");
//        $query = $collection->getSelect()->__toString();
//        echo $query;

        return $this;
    }

1 个答案:

答案 0 :(得分:0)

它不是关于filter_condition_callback函数,

Magento网格不允许使用群组声明。因此,您的分页和过滤器会被破坏。