3

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

1
  • Did you try Google? – pspahn Jun 23 '14 at 17:09
3

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');
    }
}
}
0

Firstly you will need to rewrite the block Mage_Adminhtml_Block_Catalog_Product_Grid and make the following changes.

  1. Rewrite the function _prepareCollection so that it adds the attribute weight to the select,
  2. Rewrite the function _prepareColumns so that a new column is added to the grid for the attribute width

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.