1

In Magento Admin, when we go to Catalog > Manage Products, We see the list of Products of all types by Default as shown as below image:-

enter image description here

but I want to show only Configurable Type Product by Default View.

Is there a way to do it.? Please anyone help me.

Thanks in Advance.

2

Let's create a new module with a module declaration file:

app/etc/modules/Shashank_Adminhtml.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Shashank_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Adminhtml/>
            </depends>
        </Shashank_Adminhtml>
    </modules>
</config>

Create your module directory structure and a config.xml:

app/code/local/Shashank/Adminhtml/etc/config.xml

<?xml version="1.0"?>
<config>
</config>

We need to rewrite a block inside the admin panel, so let's turn on template hints in the admin. In our config.xml:

<?xml version="1.0"?>
<config>
    <stores>
        <admin>
            <dev>
                <debug>
                    <template_hints>1</template_hints>
                    <template_hints_blocks>1</template_hints_blocks>
                </debug>
            </dev>
        </admin>
    </stores>
</config>

The grid container we want to override is: Shashank_Adminhtml_Block_Catalog_Product_Grid

Let's rewrite our block with the rewrite node inside our config.xml:

<?xml version="1.0"?>
<config>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_product_grid>Shashank_Adminhtml_Block_Catalog_Product_Grid</catalog_product_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
    <stores>
        <admin>
            <dev>
                <debug>
                    <template_hints>1</template_hints>
                    <template_hints_blocks>1</template_hints_blocks>
                </debug>
            </dev>
        </admin>
    </stores>
</config>

Let's create a class that rewrites that block. We will use: Shashank_Adminhtml_Block_Catalog_Product_Grid.

<?php

class Shashank_Adminhtml_Block_Catalog_Product_Grid 
    extends Mage_Adminhtml_Block_Catalog_Product_Grid {

}

Now, with our template hints still on, let's check to see that it's being rewritten. Rewritten block class

Now, all we have to do is set our default sort attributes and default filters. We will do that in the __construct() method of our class.

<?php

class Shashank_Adminhtml_Block_Catalog_Product_Grid 
    extends Mage_Adminhtml_Block_Catalog_Product_Grid {


    public function __construct() {
        parent::__construct();
        $this->setDefaultSort('type');
        $this->setDefaultFilter(array('type' => 'configurable'));

    }
}

Now, turn off the template hints and see that it's being rewritten.

Default Sort

I hope this helps.

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.