3

I have a product collection that use a addAttributeToSort.

Now there exists a sort filter in the frontend to sort products e.g. for price or date.

When I click that filter in the frontend I have to reset my first order by. But now the problem is I can only reset the order after the frontend runs his new order.

So my question is there a possibility to reset only specific order by columns or can I only reset all order at once?

8

The available sorting methods are

addOrder(), setOrder(), unshiftOrder(), addAttributeToSort() and getSelect()->order()

Only setOrder($field, $dir) is available regardless of collection type and system settings. I suggest you get used to using setOrder().

If you need to enforce an order, but an order is already set on the collection, use unshiftOrder($field, $dir) for flat table collections.

For EAV collections you need to do

$col->getSelect()->reset(Zend_Db_Select::ORDER); And then use $col->setOrder($field, $dir);

Resource: http://tweetorials.tumblr.com/post/11137227678/magento-collection-ordering-or-sorting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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