Magento2: Sort by Price not working on CatalogSearch Page in Magento 2

Created on 28 Nov 2017  路  7Comments  路  Source: magento/magento2

I have setup Magneto ver 2.1.9. I got an issue on catalogsearch page that sort by price not working after change Product Listing Sort by Price from magento backend.

Preconditions

  1. Magneto ver. 2.1.9
  2. PHP ver. 7.0.25

Steps to reproduce

  1. Go to stores -> catalog -> catalog -> storefront -> Product Listing Sort by -> Price
  2. Save Config

Expected result

  1. Go to website and search any product
  2. By default result sorted by relevance. When change sorting from relevance to price the result should be sorted with price and in sorting dropdown price should select.

Actual result

  1. Go to website and search any product
  2. By default result sorted by relevance but when change sorting from relevance to price the result still sorted with relevance and in sorting dropdown relevance is selected.


I have also submit issue on magento stackexchange but I got suggestion to generate ticket on github.
https://magento.stackexchange.com/questions/203511/sort-by-price-not-working-on-catalogsearch-page-in-magento-2

Fixed in 2.2.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x

Most helpful comment

hi @isavchuk-magento, is the patch going to be available for 2.1.x?

All 7 comments

@kapildev-symberity, thank you for your report.
We've created internal ticket(s) MAGETWO-57945 to track progress on the issue.

Hi @kapildev-symberity
The fix for this issue is now delivered to the 2.2-develop and should be released with the next patch release.
Thank you for collaboration.

hi @isavchuk-magento, is the patch going to be available for 2.1.x?

Can someone please share the patch for this fix. thanks,

does anyone know the solution to this problem? :)

Hello, I think I have located the fix in the code base:

In magento/module-catalog/Block/Product/ProductList/Toolbar.php

Replace
'orderDefault' => $this->_productListHelper->getDefaultSortField(),

With
'orderDefault' => $this->getOrderField(),

See this commit
https://github.com/magento/magento2/commit/4091835d49d852cdbf181bee52284688be3a427a

It would be best practice to write a small module to override this block.

Hope this helps
Adam

Hello, I think I have located the fix in the code base:

In magento/module-catalog/Block/Product/ProductList/Toolbar.php

Replace
'orderDefault' => $this->_productListHelper->getDefaultSortField(),

With
'orderDefault' => $this->getOrderField(),

See this commit
4091835

It would be best practice to write a small module to override this block.

Hope this helps
Adam

Thanks @plumbingworld

I tried your code and it fixed my problem on store running Magento 2.2.2

Thanks!!!

Was this page helpful?
0 / 5 - 0 ratings