The @Ivan Chepurnyi method worked, but it returns a ReflectionObject, in my case I need Varien_Data_Collection.
Here is what I did instead
$collectionItems = $collection->getItems(); usort($collectionItems, array($this, '_sortItems')); $newCollection = new Varien_Data_Collection(); foreach ($collectionItems as $item) { $newCollection->addItem($item); } var_dump($newCollection);
And in this case, the sorting method
public function _sortItems($a, $b) { $columnId = "your_column_that_you_need_to_sort"; $dir = "desc"; $al = strtolower($a->getData($columnId)); $bl = strtolower($b->getData($columnId)); if ($al == $bl) { return 0; } if ($dir == 'asc') { return ($al < $bl) ? -1 : 1; } else { return ($al > $bl) ? -1 : 1; } }
Shadowbob
source share