Add categories column to the product grid in Magento admin

后端 未结 5 1335
梦如初夏
梦如初夏 2021-02-02 00:19

I\'m trying to add a category column to the product grid. I\'ve modified Mage_Adminhtml_Block_Catalog_Product_Grid. Added the following to _prepareCollection<

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 00:51

    Per the quote above.

    The filter and sortable flags will prevent the column header to be clickable and also remove the filter text box for that column. Since we have done some heavy workarounding to get the categories column into the grid, these features won’t work anyway. I don’t need them, therefore I have not looked into how hard it is to make them work.

    All you need to do is paste the code below

        $collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('name');
    $options = array();
    foreach ($collection as $item){
        if($item->getId() != ''){
        $options[$item->getId()] = $item->getName();
    }
    }
    
    $this->addColumn('category_ids',
            array(
                'header'   => Mage::helper('catalog')->__('Categories'),
                'index'    => 'single_category_id',
                'width'    => '150px',
                'type' => 'options',
                 'options'  => $options
    ));
    

    in place of

    $this->addColumn('category_ids',
        array(
            'header'   => Mage::helper('catalog')->__('Categories'),
            'index'    => 'category_names',
            'width'    => '150px',
            'filter'   => false,
            'sortable' => false,
    

    ));

提交回复
热议问题