I am in the process of sorting products by attribute_set_id with the help of a custom module that extends Mage_Catalog_Model_Config. Here is my module's Model/Catalog/Config.php


class Atwix_Tweaks_Model_Catalog_Config extends Mage_Catalog_Model_Config
    public function getAttributeUsedForSortByArray()
        $options = array(
            'attribute_set_id' => Mage::getModel("eav/entity_attribute_set")

        foreach ($this->getAttributesUsedForSortBy() as $attribute) {
            $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();

        return $options;

After sorting by attribute_set_id, I want to sort by product name so I attempt to add this to the array:

        $options = array(
            'attribute_set_id' => Mage::getModel("eav/entity_attribute_set"),
            'name' => Mage::helper('catalog')->__('Name')

But the catalog page doesn't seem to recognize the second field. I can only ever get one field to work. This is the meat of my extension and all customizations are in this single file. This is the link that the extension is based on: http://www.atwix.com/magento/custom-sorting-product-listing/

Is there another way to use mixed attributes in a collection array? I feel like I'm looking over something.

1 Answer 1


You need to rewrite the method Mage_Catalog_Model_Resource_Product_Collection::addAttributeToSort.
Add your own logic for attribute_set_id.
Something like this:

public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC){
    if (Mage::app()->getStore()->getId() == Mage_Core_Model_App::ADMIN_STORE_ID)    
        return parent::addAttributeToSort($attribute, $dir);
    //sort normally
    parent::addAttributeToSort($attribute, $dir);
    //if sorting my attribute_set_id, sort by name also
    if ($attribute == 'attribute_set_id') {
         $this->addAttributeToSort('name', $dir);
    return $this;


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.