Does anyone know how I can add a weight column to the Catalog, Manage Products, Admin Panel? ID, NAME, TYPE-ATTRIB. SET NAME, SKU, PRICE, QTY, VISIBILITY, STATUS, WEIGHT
Yes you can write a simple module in fifteen minutes that will do this for you (without rewrites)
Thanks to @Narno for his answer: Adding columns to customer grid using observer or overriding the customer grid
I added some slight modifications so it should work for the products grid.
The Observers way:
Declare 2 observers in your config.xml file: one to add your column to the grid block and the other one to load data from the corresponding attribute:
<adminhtml>
<events>
<core_block_abstract_to_html_before>
<observers>
<{observer_name}>
<type>singleton</type>
<class>{namespace}_{module}/observer</class>
<method>beforeBlockToHtml</method>
</{observer_name}>
</observers>
</core_block_abstract_to_html_before>
<eav_collection_abstract_load_before>
<observers>
<{observer_name}>
<class>{namespace}_{module}/observer</class>
<method>beforeCollectionLoad</method>
</{observer_name}>
</observers>
</eav_collection_abstract_load_before>
</events>
</adminhtml>
Create an Observer class with appropriate methods:
class {Namespace}_{Module}_Model_Observer
{
public function beforeBlockToHtml(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if ($block->getType() == 'adminhtml/catalog_product_grid') {
$block->addColumnAfter('status', array(
'header' => 'Name to show on top',
'type' => 'text',
'index' => 'weight',
), 'sku');
}
}
public function beforeCollectionLoad(Varien_Event_Observer $observer)
{
$collection = $observer->getCollection();
if (!isset($collection)) {
return;
}
/**
* Mage_Catalog_Model_Resource_Product_Collection
*/
if ($collection instanceof Mage_Catalog_Model_Resource_Product_Collection) {
/* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
$collection->addAttributeToSelect('weight');
}
}
}
Firstly you will need to rewrite the block Mage_Adminhtml_Block_Catalog_Product_Grid
and make the following changes.
- Rewrite the function
_prepareCollection
so that it adds the attributeweight
to the select, - Rewrite the function
_prepareColumns
so that a new column is added to the grid for the attributewidth