0

a question in two parts: Firstly, for my own understanding, where are the setSortBy and setDefaultDirection methods for the search result blocks? These are all available to set in the layout xml (e.g. catalogsearch.xml) but I am unable to locate the actual methods inside any of the search blocks like I can with the setListOrders() method. Are these just examples of the magic methods approach to these set______ function calls? If so where are these properties stemming from?

Secondly, how does one set the sortBy to sort with two fields? I am looking to sort by product type "Grouped" then "Simple" and then by another parameter - in my case manufacturer.

<reference name="search_result_list">
    <action method="setDefaultDirection"><param>asc</param></action>
    <action method="setSortBy"><param>manufacturer</param></action>
</reference>

Thanks

Jon

1

Are these just examples of the magic methods

Yes. If you find setSomething as layout action, search the blocks and templates for getSomething to see where it is used: getSortBy

how does one set the sortBy to sort with two fields

This is not possible out of the box, you would need to rewrite Mage_Catalog_Block_Product_List_Toolbar, specifically the setCollection() method. Then, if getCurrentOrder() which is the value from your layout XML, returns an array, comma separated list or however you want to define it, apply the multiple sort order to the collection:

You can call $collection->setOrder($field, $direction); two times with different fields to order by both fields.

  • thanks for the reply fschmengler. I had kind of reached the conclusion about doing it with the collection. – Jon Holland Oct 30 '15 at 10:03

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.