2

I am trying to display the search result sorted by attribute_set_id.

I want to display them with the title as the name of the first attribute_set and then all the products that belong to attribute_set_id 1 and then title of attribute_set 2 and then the products in attribute set 2.

Any one got an idea on how i can make this happened?

I have tried to sort the result list by the following code

<?php $_productCollection = clone $this->getLoadedProductCollection();

$_productCollection->clear()
    ->addAttributeToSelect('*')
    ->addAttributeToSort('attribute_set_id', 'DESC')
    ->load();
?>   
1
  • Please tell me, that the code you showed us are not in any template. Wherever it is, it looks like you are loading the collection, then clears it, add the attributes and sorting and reloads it. Adding all attributes is a bad idea and loading the collection twice is a bad idea too. Commented Nov 10, 2013 at 22:42

1 Answer 1

2

Try to use ->setOrder('attribute_set_id', 'DESC') because ->addAttributeToSort applies to EAV types only

setOrder($field, $direction = self::SORT_ORDER_DESC) is from Varien/Data/Collection.php so should work fine

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.