3

I want to add a custom attribute to the Admin Product Grid. The attribute got the attribute code import_price.

How can we add this column?

5

There is already one flexible module in github for managing grid columns of any entities(orders, products, customers etc.):
https://github.com/magento-hackathon/GridControl

3

Found this question using Google, the selected answer works but I just tried out this module and wanted to share. It installs through Magento Connect and works extremely well.

(dead link) http://www.magentocommerce.com/magento-connect/enhanced-admin-grids-editor.html new link: https://github.com/mage-eag/mage-enhanced-admin-grids

  • This works very well. I also use this as a means to quickly create reports. Example usage case: get a list of all products with no images. For tgat i simply add to grid the correct image attributes, then filter on that for 'no image' and then export result to csv. Bang. Done. No time spending coding this. Since our content managers now understand how to do this, i hardly ever need to custom code scripts to pull data related reports. – ProxiBlue Jan 21 '16 at 23:47
  • 1
    Link doesnt work anymore. – sv3n Feb 8 '18 at 12:17
  • I cant find the original author anymore - do I just delete the answer? – SR_Magento Feb 9 '18 at 13:18
0

Note: A better solution is a module approach, like in the accepted answer.

I used this blog and that works great! [link] - Jelle

Here's the gist of that post:

Copy the contents of: /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php into a new file (if it doesn't exist): /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

Find this:

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

Below that, add the attribute you want in your admin product grid:

$this->addColumn('import_price',
array(
    'header'=> Mage::helper('catalog')->__('Import Price'),
    'width' => '150px',
    'index' => 'import_price',
));

Find: $collection = Mage::getModel('catalog/product')->getCollection() within the _prepareCollection() function.

And add:

->addAttributeToSelect('import_price')

The article also goes into detail for adding a select dropdown list as well.

Magento: Add attribute columns in ‘Manage Products’ grid

  • This is a bad solution. By copying the core file, you make upgrading harder + security patches to this file will not get applied. – Wouter Jan 21 '16 at 13:37
  • The module approach is better. – Dan Sandland Jan 21 '16 at 23:20
0

Add below code to select attribuet in _prepareCollection function of product grid Mage_Adminhtml_Block_Catalog_Product_Grid before $this->setCollection($collection) line.

$attributeCode = 'qc_status';//here your attribute code
        $collection->joinAttribute($attributeCode, 'catalog_product/'.$attributeCode, 'entity_id', null, 'left');
        $collection->addAttributeToSelect($attributeCode);

And then below code for column in _prepareColumns function of grid.

$attributeCodeConfig ='qc_status';//Your attribute code...

        $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $attributeCodeConfig);

        $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
        $attributeData = $attribute->getData();
        $frontEndLabel = $attributeData['frontend_label'];

        $attributeOptions = $attribute->getSource()->getAllOptions();
        $b = new Mage_Catalog_Model_Resource_Eav_Attribute();
        $attributeOptions2 = array();
        foreach ($attributeOptions as $value) {
            if(!empty($value['value'])) {
                $attributeOptions2[$value['value']] = $value['label'];
            }

        }


        if(count($attributeOptions2) > 0) {
            $this->addColumn($attributeCodeConfig,
                array(
                    'header'=> Mage::helper('catalog')->__($frontEndLabel),
                    'width' => '80px',
                    'index' => $attributeCodeConfig,
                    'type'  => 'options',
                    'options' => $attributeOptions2,

            ));
        } else {
            $this->addColumn($attributeCodeConfig,
                array(
                    'header'=> Mage::helper('catalog')->__($frontEndLabel),
                    'width' => '80px',
                    'index' => $attributeCodeConfig,

            ));
        }

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.