Jump to content

Default order by - Sort by - customization


Mateusz321

Recommended Posts

In all categories products are sorted according to the default filter Sort by: New products first, I would like to know if it's possible to set some categories sorting on the position ''Random''? For example, the category: home, cars, pets should be set to ''New products first''
while the category flowers on ''Random''. Thank you

sortby.jpg

Link to comment
Share on other sites

in classes/controller/ProductListingFrontController.php file, getProductSearchVariables() is used to return the product listing for category page.

Replace

if (($encodedSortOrder = Tools::getValue('order'))) {
            $query->setSortOrder(SortOrder::newFromString(
                $encodedSortOrder
            ));
        }

with

if (($encodedSortOrder = Tools::getValue('order'))) {
            $query->setSortOrder(SortOrder::newFromString(
                $encodedSortOrder
            ));
        } else {

$query->setSortOrder(SortOrder::newFromString(
                ["Your sorting method"]
            ));

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...