I've created a module that is intended to allow me to add custom sort features to my catalog pages (my product collection). For whatever reason, it returns my collection no problem but fails to honor any form of sort that I apply to it. Here is my Observer.php code

//File: app/code/local/MyExtensions/Attsetfilter/Model/Observer.php

class MyExtensions_Attsetfilter_Model_Observer
    public function load_productsby_attributesetid($observer) {
        $collection = $observer->getCollection();
        $collection->addAttributeToSort('attribute_set_id', 'asc');
        echo "Extension is being called";
        return $collection;

I know my product collection is being passed through here because if I comment out the first line of my public function ("$collction = ...") it returns nothing. I've attempted to add filters to the function like so

        $collection->addAttributeToSort('attribute_set_id', 'asc');

But it never seems to honor them. I've seen other methods of filtering a product collection such as:

$collection = $this->getCollection()
        ->setOrder('fieldname', 'asc')

But that snippet won't work in my extension code either. Is there something obvious that I am doing wrong? Thanks in advance.

EDIT: Here is my modules config.xml file as well:

<?xml version="1.0"?>

3 Answers 3


Is there something obvious that I am doing wrong?

Yes, you observe catalog_product_collection_load_after instead of catalog_product_collection_load_before. At this point the collection is already loaded from the database.

  • Switching it to "before" instead of "after" seems to stop it from functioning all together.
    – sparecycle
    Feb 12, 2015 at 14:39
  • what do you mean? Feb 12, 2015 at 16:13

Try using getSelect()->order() like this:

$collection->getSelect()->order('attribute_set_id asc');
  • I'm afraid that doesn't have any affect on sorting. Is it by chance supposed to be setOrder?
    – sparecycle
    Feb 11, 2015 at 20:18
  • No, it's order(). I've had it work for me in the past when other methods failed. Feb 11, 2015 at 20:20
  • Gotcha. Thanks anyways. Maybe there is something I'm overlooking.
    – sparecycle
    Feb 11, 2015 at 20:22
  • Is it not honoring ANY field that you try sort by or just that one? Maybe attribute_set_id isn't a loaded attribute for the collection. You could try $collection->addAttributeToSelect('*') prior to your sort statement to see if that helps. Feb 11, 2015 at 20:42
  • Not sorting for anything. Let me try that...
    – sparecycle
    Feb 11, 2015 at 20:43

I faced the same problem.Make sure order_no is stored as Integer in database.That was the mistake I made. Try this one.


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.