How to Sort Attribute Set List on Manage Products Grid Dropdown

attribute-setmagento-1.8products-management

We are using Magento 1.8.1. When I navigate to the Catalog > Manage Products grid view of our products, I see the Attribute Set column, which displays as a selectable dropdown menu.

The challenge we are having is that our list of attribute sets is quite long, and they are ordered in order of when they were created (so I assume they are ordered by their attribute_set_id or something like that).

I would like to re-sort this list alphabetically, so that if I wish to find a specific attribute set, I simply look through an alphabetized list, rather than having to scroll up and down like crazy to find the attribute set I need.

I appreciate any guidance you can provide.

Thanks.

Best Answer

Step 1: Create app/etc/modules/MyProject_Catalog.xml

Contents:

<?xml version="1.0"?>
<config>
    <modules>
        <MyProject_Catalog>
            <active>true</active>
            <codePool>local</codePool>
        </MyProject_Catalog>
    </modules>
</config>

Step 2: Create app/code/local/MyProject/Catalog/etc/config.xml

Contents:

<?xml version="1.0"?>
<config>
    <modules>
        <MyProject_Catalog>
            <version>1.0.0</version>
        </MyProject_Catalog>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_product_grid>MyProject_Catalog_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

Step 3: Create app/code/local/MyProject/Catalog/Block/Adminhtml/Catalog/Product/Grid.php

Contents:

<?php
class MyProject_Catalog_Block_Adminhtml_Catalog_Product_Grid 
    extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
    public function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->removeColumn('set_name');

        $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
            ->setOrder('attribute_set_name', 'asc')
            ->load()
            ->toOptionHash();

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

        $this->sortColumnsByOrder();

        return $this;
    }
}

Step 4 Clear 'configuration' cache type if enabled.

Related Topic