I'm trying sort products in category page by position. But Magento2 does not react to changes.

enter image description here

Any ideas how can I fix it?

  • How do you take the collection? Try adding addAttributeToSort('attribute_code', 'sort_order') Feb 24, 2018 at 16:21

1 Answer 1


It is Magento2.2 default bug. Please follow this to solve your problem.

Create etc/di.xml file.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection" type="Vendor\Module\Model\ResourceModel\Fulltext\Collection" />

Create Vendor\Module\Model\ResourceModel\Fulltext\Collection.php file. Copy core Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection.php file in your module and put below code in that file.

Replace line no. 366 to 388 in Collection.php.

            'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
    return parent::_renderFiltersBefore();

 * @inheritdoc
protected function _beforeLoad()
    * This order is required to force search results be the same
    * for the same requests and products with the same relevance
    * NOTE: this does not replace existing orders but ADDs one more

    return parent::_renderFiltersBefore();
    return parent::_beforeLoad();

  • Please update full file Sep 10, 2018 at 12:29
  • It doesn't work. Just tested on mag 2.2.3. Plz share your complete code.
    – Ahsan
    Jan 1, 2019 at 16:16
  • does Magento have more default bugs ? :) Apr 16, 2021 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.