Using Magento CE

We're trying to find a way to sort products on our site based on which attribute set they were created with. We sells clothes on our site so we have a number of attribute sets such as hats, pants, tees, accessories, etc..

I have the means to sort by attribute:

$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToSort('display_order', 'ASC');
$_helper = $this->helper('catalog/output'); 

But this covers attributes within an attribute set. Is there a way to include an "attribute set" field into the catalog template for sorting? I'm currently working with app/design/frontend/mypackage/mytheme/template/catalog/product/list.phtml.

Example: We have a "New" page where products from all the various categories will show. You'll see a new hat, new t-shirt, new pants, etc. but we would like all the new hats to be grouped together (which would be done by sorting attribute set), pants to be together, t-shirts, and so.

**EDIT: ** I found a way to access the product object's attribute set... https://stackoverflow.com/questions/2091375/how-do-i-get-attribute-set-name Now I just to know how to sort by that piece of data.

2 Answers 2


I had used observer for this in your custommodule and in that etc/config.xml under <global> tag use:


Also in custommodule/Model/Obeserver.php under your modules Model folder add following code

    class Yourpackagename_Yourmodulename_Model_Observer{
        public function load_productsby_attributesetid($observer){
            $collection = $observer->getCollection();
            $collection->addAttributeToSelect('*')->addAttributeToSort('attribute_set_id', 'asc');
            return $collection;
  • I have created the custom module and swapped the naming with my own. How do I make use of this function? Do I execute it on the catalog template of my choosing?
    – sparecycle
    Commented Feb 4, 2015 at 21:51
  • just check my edited answer Commented Feb 5, 2015 at 4:02
  • I get that part. But I try to call the function load_productsby_attributesetid() from my list.phtml file and it seems to be undefined.
    – sparecycle
    Commented Feb 5, 2015 at 6:40
  • dont call load_productsby_attributesetid() in your list.phtml Commented Feb 5, 2015 at 6:42
  • justr add this above 2 content at to flies that it.dont call method.rest is done Commented Feb 5, 2015 at 6:43

You can try sorting by 'attribute_set_id'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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