筛选器计数列 Magento 客户管理网格与filter_condition_callback


Filter count column Magento Customer Admin grid with filter_condition_callback

我已经修改了 ../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'),
    ));

订单总筛选器回调:

    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;
    }

与filter_condition_callback函数无关,

Magento 网格不允许组语句。因此,您的分页和过滤器已损坏。