PHP Magento Tips

Add New Column in Manage Categories in Category Product Tab in Magento

Rate this posting:
{[['']]}

Magento has product type column is already added in manage products grid, however it wasn’t included in category product tab in manage categories.

Here we will add product type as well as product's special price column in catalog >> Manage Categories Category Products tab.

You can do it with below step:

The file that you need to modify is located in
/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php

Simply create a local copy of it, so that it will not be affected when updaing magento.

The local copy should be located with this path
/app/code/local/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php

Find _prepareCollection function

Modify its code as per below highlighted code.

$collection = Mage::getModel('catalog/product')->getCollection()

            ->addAttributeToSelect('name')

            ->addAttributeToSelect('sku')

            ->addAttributeToSelect('price')

            ->addAttributeToSelect('type_id')

            ->addStoreFilter($this->getRequest()->getParam('store'))

            ->joinField('position',

                'catalog/category_product',

                'position',

                'product_id=entity_id',

                'category_id='.(int) $this->getRequest()->getParam('id', 0),

                'left');

$collection->joinAttribute('special_price', 'catalog_product/special_price', 'entity_id', null, 'left');

$this->setCollection($collection);

Next is in the _prepareColumns function.

we just have to add these piece of code.  For product type I’ve added it next to name column. And for Special price I’ve added it next to price column.

$this->addColumn('type',

          array(

            'header'=> Mage::helper('catalog')->__('Type'),

            'width' => '120',

            'index' => 'type_id',

            'type' => 'options',

            'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),

));



$this->addColumn('special_price', array(

          'header' => Mage::helper('catalog')->__('Special_price'),

          'type' => 'currency',

          'width' => '30px',

          'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),

          'index' => 'special_price'

));

Now go to Catalog >> Manage Categories and Under Category Products tab you will fine two new columns as per below screenshot.


Tag : Magento
0 Comments On "Add New Column in Manage Categories in Category Product Tab in Magento"

Back To Top