I would like to put an Attribute called "Volume" to my Magento Online Shop. Products should be sorted by this attribute and it should be filterable through the layered navigation. since text attributes are not filterable in layered navigation and multi select fields not sortable i actually dont know how to acomplish that. any idea maybe ? i was thinking about a price attribute but then it would be there in EUROs not in Liters for example...

  • Dropdown is the only type allowing filtering as well as sorting iirc. Any reason for not using it?
    – pong
    Nov 20, 2016 at 16:50
  • i tried it but i cant sort it realy nummerical. its alphanummerical. for example when i got values like 1 2 4 100 1000 it sorts it like 1 100 1000 2 4 instead of 1 2 4 100 1000. Is there a fix for that bug for dropdown attributes ? i allready fixed that for a text attribute but is there a fix for dropdown too ?
    – Magneto23
    Nov 20, 2016 at 17:12

1 Answer 1


You can override the order in an observer and provide SQL that takes numeric values into account. This is some kind of a workaround since Magento doesn't allow for elegant sort order modification.


Observer definition listening to event catalog_product_collection_load_before – i.e. last one before query gets rendered:



public function setSortOrder (Varien_Event_Observer $observer)
    $numericallySortedAttributeCode = 'test_attribute';

    $request = Mage::app()->getRequest();
    $order = $request->getParam ( 'order' );

    if ( $order == $numericallySortedAttributeCode )
        $dir = strtoupper ( $request->getParam ( 'dir' ) );
        $dir = in_array ( $dir, array ( Varien_Db_Select::SQL_ASC, Varien_Db_Select::SQL_DESC ) ) ? $dir : 'DESC' ;

            ->reset ( Zend_Db_Select::ORDER )
            ->order ( new Zend_Db_Expr ( 'CAST(`' . $numericallySortedAttributeCode . '` AS SIGNED) ' . $dir ) )

This is tested with attribute values of type integer. If you use alphanumeric values like '30 fl.oz.', you might have to modify the SQL CAST. You probably also wanna edit the attribute code and the condition of when to apply the sort modification – above code obviously only works if the sort order in question is sent explicitly as a request parameter aka not used implicitly as default sort order.

Your Answer

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

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