Magento Themes and Magento Extensions

How to add new column of product list page in admin section of magento

Share

How to add new column of product list page in admin section of magento.

At first open the following file
app\code\core\mage\adminhtml\block\catalog\product\grid.php

I have added new two column in product listing page in admin section. The code which i modified is given below.

Then to go protected function _prepareCollection() method

protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel(‘catalog/product’)->getCollection()
->addAttributeToSelect(‘sku’)
->addAttributeToSelect(‘name’)
->addAttributeToSelect(‘attribute_set_id’)
->addAttributeToSelect(‘type_id’)
->joinField(‘qty’,
‘cataloginventory/stock_item’,
‘qty’,
‘product_id=entity_id’,
‘{{table}}.stock_id=1′,
‘left’)
->joinField(‘qty1′,
‘cataloginventory/stock_status’,
‘qty’,
‘product_id=entity_id’,
‘{{table}}.stock_id=1′,
‘left’);

if ($store->getId()) {
//$collection->setStoreId($store->getId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute(‘name’, ‘catalog_product/name’, ‘entity_id’, null, ‘inner’, $adminStore);
$collection->joinAttribute(‘custom_name’, ‘catalog_product/name’, ‘entity_id’, null, ‘inner’, $store->getId());
$collection->joinAttribute(‘status’, ‘catalog_product/status’, ‘entity_id’, null, ‘inner’, $store->getId());
$collection->joinAttribute(‘visibility’, ‘catalog_product/visibility’, ‘entity_id’, null, ‘inner’, $store->getId());
$collection->joinAttribute(‘price’, ‘catalog_product/price’, ‘entity_id’, null, ‘left’, $store->getId());
$collection->joinAttribute(‘cost’, ‘catalog_product/price’, ‘entity_id’, null, ‘left’, $store->getId());
}
else {
$collection->addAttributeToSelect(‘price’);
$collection->addAttributeToSelect(‘cost’);
$collection->joinAttribute(‘status’, ‘catalog_product/status’, ‘entity_id’, null, ‘inner’);
$collection->joinAttribute(‘visibility’, ‘catalog_product/visibility’, ‘entity_id’, null, ‘inner’);
}

$this->setCollection($collection);

parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
// var_dump($this) ;
// die(‘aaa’) ;
return $this;
}

protected function _prepareColumns()
{
$this->addColumn(‘entity_id’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘ID’),
‘width’ => ’50px’,
‘type’  => ‘number’,
‘index’ => ‘entity_id’,
));
$this->addColumn(‘name’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Name’),
‘index’ => ‘name’,
));

$store = $this->_getStore();
if ($store->getId()) {
$this->addColumn(‘custom_name’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Name in %s’, $store->getName()),
‘index’ => ‘custom_name’,
));
}

$this->addColumn(‘type’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Type’),
‘width’ => ’60px’,
‘index’ => ‘type_id’,
‘type’  => ‘options’,
‘options’ => Mage::getSingleton(‘catalog/product_type’)->getOptionArray(),
));

$sets = Mage::getResourceModel(‘eav/entity_attribute_set_collection’)
->setEntityTypeFilter(Mage::getModel(‘catalog/product’)->getResource()->getTypeId())
->load()
->toOptionHash();

$this->addColumn(‘set_name’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Attrib. Set Name’),
‘width’ => ’100px’,
‘index’ => ‘attribute_set_id’,
‘type’  => ‘options’,
‘options’ => $sets,
));

$this->addColumn(‘sku’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘SKU’),
‘width’ => ’80px’,
‘index’ => ‘sku’,
));

$store = $this->_getStore();
$this->addColumn(‘price’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Price’),
‘type’  => ‘price’,
‘currency_code’ => $store->getBaseCurrency()->getCode(),
‘index’ => ‘price’,
));

$store = $this->_getStore();
$this->addColumn(‘cost’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Cost’),
‘type’  => ‘price’,
‘currency_code’ => $store->getBaseCurrency()->getCode(),
‘index’ => ‘cost’,
));

$this->addColumn(‘qty’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Qty’),
‘width’ => ’100px’,
‘type’  => ‘number’,
‘index’ => ‘qty’,
));

$this->addColumn(‘qty1′, array(
‘header’    => Mage::helper(‘sales’)->__(‘In Stock’),
‘width’     => ’80′,
‘type’      => ‘number’,
‘name’      => ‘qty1′,
‘index’     => ‘qty1′,

));

$this->addColumn(‘visibility’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Visibility’),
‘width’ => ’70px’,
‘index’ => ‘visibility’,
‘type’  => ‘options’,
‘options’ => Mage::getModel(‘catalog/product_visibility’)->getOptionArray(),
));

$this->addColumn(‘status’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Status’),
‘width’ => ’70px’,
‘index’ => ‘status’,
‘type’  => ‘options’,
‘options’ => Mage::getSingleton(‘catalog/product_status’)->getOptionArray(),
));

if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn(‘websites’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Websites’),
‘width’ => ’100px’,
‘sortable’  => false,
‘index’     => ‘websites’,
‘type’      => ‘options’,
‘options’   => Mage::getModel(‘core/website’)->getCollection()->toOptionHash(),
));
}

$this->addColumn(‘action’,
array(
‘header’    => Mage::helper(‘catalog’)->__(‘Action’),
‘width’     => ’50px’,
‘type’      => ‘action’,
‘getter’     => ‘getId’,
‘actions’   => array(
array(
‘caption’ => Mage::helper(‘catalog’)->__(‘Edit’),
‘url’     => array(
‘base’=>’*/*/edit’,
‘params’=>array(‘store’=>$this->getRequest()->getParam(‘store’))
),
‘field’   => ‘id’
)
),
‘filter’    => false,
‘sortable’  => false,
‘index’     => ‘stores’,
));

$this->addRssList(‘rss/catalog/notifystock’, Mage::helper(‘catalog’)->__(‘Notify Low Stock RSS’));

return parent::_prepareColumns();
}

Comments are closed.