0

I am not able to override the Search.php file by using preference in magento 2.3.4. Below is the my di.xml file. Please anybody can check the below code.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\Search\Search" type="Candere\Sortfix\Search\Search" /> </config> 
2
  • did you run di:compile Commented May 3, 2022 at 5:38
  • I run the setup:upgrade and di:compile. Commented May 3, 2022 at 5:41

1 Answer 1

2

You can only specify preferences for classes that get instantiated. From what I see, the class Magento\Framework\Search\Search does not get instantiated. It is only extended by the class Magento\Search\Model\Search which gets instantiated. (it is a preference for Magento\Search\Api\SearchInterface).

You can either add a preference for this model

<preference for="Magento\Search\Model\Search" type="Candere\Sortfix\Search\Search" /> 

or you can add a preference for Magento\Search\Api\SearchInterface

<preference for="Magento\Search\Api\SearchInterface" type="Candere\Sortfix\Search\Search" /> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.