Skip to content

How to override core codes – Magento 2.4.3

I have this issue with my Magento 2.4.3 where it does not sort by position.

I found this code where I need to override, but I am quite new with Magento, is there anyone that can show me or tell me how to override:
MagentoCatalogSearchModelResourceModelFulltextCollection

The code:

protected function _renderFiltersBefore()
{
    if(isset($_SERVER['REQUEST_URI']) && !stristr($_SERVER['REQUEST_URI'], "catalogsearch")){
         $request = ObjectManager::getInstance()->create("MagentoFrameworkAppRequestInterface");
         if($request->getParam("product_list_order")){
              $attribute = $request->getParam("product_list_order", "position");
              $direction = $request->getParam("product_list_dir", "asc");
              $this->addAttributeToSort($attribute, $direction);
         }
         else{
            $this->addAttributeToSort("position", "asc");
         }
    }

As far as i can understand this should just be added and not replace anything.