filter_condition_callback在Magento观察者中不起作用

时间:2016-01-01 12:15:26

标签: magento

我正在开发一个自定义扩展程序,当我在filter_condition_callback内的观察者中使用addColumnAfter()时,它无法正常工作,请给我一些解决方案。

class CustomGrid_GeneProductGrid_Model_Observer
{

    public function beforeCollectionLoad(Varien_Event_Observer $observer)
    {
        $collection = $observer->getCollection();
        if (!isset($collection)) {
            return;
        }
        if ($collection instanceof Mage_Catalog_Model_Resource_Product_Collection) {
            $store = Mage::app()->getRequest()->getParam('store');
            $collection->joinAttribute('special_price', 'catalog_product/special_price', 'entity_id', null, 'left', $store);
            $collection->addAttributeToSelect('cost');
            $collection->addAttributeToSelect('m_cost');
        }
    }

    public function customGridHtmlBefore(Varien_Event_Observer $observer)
    {
        $store = Mage::app()->getRequest()->getParam('store');
        $grid = $observer->getBlock();
        if ($grid instanceof Mage_Adminhtml_Block_Catalog_Product_Grid) {
            if ($store == '') {
                $grid->addColumnAfter(
                    'expend_stores', array(
                    'header' => 'Expend Stores',
                    'filter' => false,
                    //'index' => 'color',
                    'width' => '25px',
                    'renderer' => 'customgrid_geneproductgrid/adminhtml_product_ExpendCollapse',
                    'align' => 'center',
                ), 'massaction'
                );
            }
            $storeId = (int)Mage::app()->getRequest()->getParam('store', 0);
            $store = Mage::app()->getStore($storeId);
            $grid->addColumnAfter(
                'cost', array(
                'header' => 'V-Cost',
                'index' => 'cost',
                'type' => 'price',
                'currency_code' => $store->getBaseCurrency()->getCode(),
                'width' => '25px',
                'align' => 'center',
            ), 'sku'
            );
            $grid->addColumnAfter(
                'm_cost', array(
                'header' => 'M-Cost',
                'index' => 'm_cost',
                'type' => 'price',
                'currency_code' => $store->getBaseCurrency()->getCode(),
                'width' => '25px',
                'align' => 'center',
            ), 'cost'
            );
            $grid->addColumnAfter(
                'special_price', array(
                'header' => 'Special Price',
                'index' => 'special_price',
                'type' => 'price',
                'currency_code' => $store->getBaseCurrency()->getCode(),
                'width' => '25px',
                'align' => 'center',
            ), 'price'
            );
            $grid->addColumnAfter('accessories_category_list', array(
                'header' => Mage::helper('catalog')->__('Category'),
                'index' => 'accessories_category_list',
                'sortable' => false,
                'type' => 'options',
                'options' => Mage::getSingleton('customgrid_geneproductgrid/system_config_source_Category')->toOptionArray(),
                'renderer' => 'customgrid_geneproductgrid/adminhtml_catalog_product_grid_render_category',
                'filter_condition_callback' => array(Mage::getSingleton('customgrid_geneproductgrid/observer'), 'filterCallback'),
            ), 'set_name');
            $grid->sortColumnsByOrder();
        }
    }

    public function filterCallback($collection, $column)
    {
        $value = $column->getFilter()->getValue();
        $_category = Mage::getModel('catalog/category')->load($value);
        $collection->addCategoryFilter($_category);

        return $collection;
    }

}

0 个答案:

没有答案