Magento2: Changing sort order in admin doesn't work for catalog search

Created on 21 Jul 2016  路  34Comments  路  Source: magento/magento2

I am not sure if this is an issue, If not please consider it as a question.

Steps to reproduce

  1. Login to magento store admin
  2. Navigate to Stores->Configuration->Catalog->Catalog->Storefront
  3. Change Product Listing Sort by to Price
  4. Goto magento store frontend and search by keyword

    Expected result

  5. Default sorting should be price

    Actual result

  6. Default sorting is relevance

Clear Description Confirmed Format is not valid Ready for Work PR Created Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report good first issue

Most helpful comment

Place this hidden input in form.mini.phtml

<input type="hidden" name="product_list_order" value="name" />

All 34 comments

Hello! Please, provide your code base version

I am using magento 2.0.7

additionally, if "Sort by" is _not_ "Position", switching the search results order fails for "Name" or "Price" (depending what you set as "Sort by"). Magento 2.1.0 CE

Hi guys,

Thanks for reporting this. I have created internal ticket MAGETWO-57945 to fix this bug. This issue will be closed after fix

Hi @sneha-sukumaran, default search setting is not affected in search because in catalog search magento by default add sort option by "Relevance".

Is there any update on this?
Same issue in 2.1.2.

/cc @AzVo @oserediuk @olysenko

Additionally/Related, 'Relevance' is notably absent on the backend. It's injected as a selection in the Search sorting options, but there's no way to actually make it default without directly updating core_config_data.

We use ElasticSearch and don't want Magento to reorder those results (unless explicitly changed by the sorting dropdown).

@morgon
I remember it when you talk about elasticsearch, we are using https://github.com/Smile-SA/elasticsuite . If i disable that module, sorting in categories working as expected (default, order by position desc). May be it is a clue about this issue.

Just wanted to share my workaround for the issue that @heldchen mentioned, with the search results not letting you select your store's default sorting method.
We changed our default sort by to SKU, and in search results, we were no longer able to select Sort By SKU, as it seemed to retain this as the default somewhere even though the actual default is 'relevance'. I found that this issue has to do with the JSON array in the toolbar. I guess the JS uses this to determine whether to change the query in the URI.
I don't really know the details of how it all works, but after trying a few things, this actually worked for me. Perhaps someone can propose a better option.

Modify vendor/magento/module-catalog/Block/Product/ProductList/Toolbar.php
Change line 685 from:
'orderDefault' => $this->_productListHelper->getDefaultSortField(),
to:
'orderDefault' => $this->_orderField ?: $this->_productListHelper->getDefaultSortField(),

Personally, I feel that the default search results SHOULD always be 'Relevance', so I'm not sure I agree with this initial issue. But hope this helps with this particular issue until it is fixed.

Sorry if my syntax isn't correct, I'm new to GitHub.

Place this hidden input in form.mini.phtml

<input type="hidden" name="product_list_order" value="name" />

Issue is still not fixed in 2.1.7

Hi,

This issue somewhat relevant to https://github.com/magento/magento2/issues/6793.

I suggested a fix there for search by 'relevance'.

@rbostan Did you manage to find a solution for elasticsearch ?

@pravalitera nope. I have talked that people in their github issues pages, they saying problem is not related with their module.

So we gave up from using Smile-SA. But researching about an improved elasticsearch wrapper.

@rbostan Ok... i have speed issues with ES... don't know if it's coming from Magento or ES...

@pravalitera if you are using configurable products, issue may be related about the way that Magento getting lowest price. You may check https://github.com/magento/magento2/issues/8428#issuecomment-278328632

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

distributed-cd

@kniemiecvirtua thank you for joining. Please accept team invitation here and self-assign the issue.

distributed-cd

@sRuchlewicz thank you for joining. Please accept team invitation here and self-assign the issue.

I do not think that this improvement has a business case. Can you provide use case?

@magento-engcom-team give me 2.3-develop instance

Hi @Santiagoebizmarts. Thank you for your request. I'm working on Magento 2.3-develop instance for you

Hi @Santiagoebizmarts, here is your Magento instance.
Admin access: https://i-5730-2-3-develop.engcom.dev.magento.com/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

mm18pl

I'd like to work on this issue:)

@mtsmtyuta thank you for joining. Please accept team invitation here and self-assign the issue.

CatalogSearch/Block/Result.php has this function
public function setListOrders()
{
$category = $this->catalogLayer->getCurrentCategory();
/* @var $category \Magento\Catalog\Model\Category */
$availableOrders = $category->getAvailableSortByOptions();
unset($availableOrders['position']);
$availableOrders['relevance'] = __('Relevance');

    $this->getListBlock()->setAvailableOrders(
        $availableOrders
    )->setDefaultDirection(
        'desc'
    )->setDefaultSortBy(
        'relevance'
    );

    return $this;
}

I think
)->setDefaultSortBy(
'relevance'
);
should use the value set in admin page instead of fixed 'relevance' if we want them to be configurable.

Hi @yuchenacidgreen. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [x] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@magento-engcom-team give me 2.3-develop instance

Hi @yuchenacidgreen. Thank you for your request. I'm working on Magento 2.3-develop instance for you

Hi @yuchenacidgreen, here is your Magento instance.
Admin access: https://i-5730-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

I implemented functionality mentioned by @sivaschenko in https://github.com/magento/magento2/pull/21119#pullrequestreview-209021416 .
Please provide any feedback, what is missing or what have I overlooked

I am closing issue due to its irrelevance.
Please, if you have a real business case when this can be helpful, please re-open the issue.

Was this page helpful?
0 / 5 - 0 ratings