Magento 2 uses default "asc" ordenation for category page and Layered Navigation. But in catalog search result page, the default direction is setted to "desc" and I've debugged the code, I've found the method configureToolbar
in \Magento\Catalog\Block\Product\ListProduct
these lines:
$dir = $this->getDefaultDirection();
if ($dir) {
$toolbar->setDefaultDirection($dir);
}
I have debugged this, following the call stack until I reach the DataObject.php
, where the default_direction
property is setted, but I don't know where this value came from, so how can I change this default direction in my search result page? Thanks in advance.
Best Answer
Classic Magento issue.
One will go through colledge and then further self educate for a decade for all the programming principles, patterns and best practices and what not.
Eventually, one will debug and will get stuck with a question like this, myself included of course. Magento certainly does not make things easy for debug.
But, I think I got that code that sets the direction. I sadly present to you
and its method
Now, you can perhaps change portions of it to
and when you hit your debug point
and in the
configureToolbar
method fromListProduct
you will see that$dir
value ishardcoded-direction
.You would expect from Magento to not hard code parameters for such an important eCommerce feature as the search is, but still, there it is.