Right now I am trying to override the default class of Magento 2 due to some my custom requirement but couldn't succeed, don't know why what I have done wrong here. May be someone can help me to the right direction.

For this I have written this code in my system,

<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection" type="COMPANY_NAME\MODULE_NAME\Model\ResourceModel\Fulltext\CatalogSearch\Collection"/> 

and I want to override this class,



di.xml [app\code\COMPANY_NAME\MODULE_NAME\etc\di.xml]

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection" type="COMPANY_NAME\MODULE_NAME\Model\ResourceModel\Fulltext\CatalogSearch\Collection"/>   


  • Have you tried to give permission for new added file "Collection.php" ? – Krupali Apr 4 '17 at 12:09
  • Yes @Krupali permission is correct :) – Keyur Shah Apr 4 '17 at 12:10

Finally I found the solution by my self, Actually It create an Issue because module CatalogSearchuse this class as virtualType in


<virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection">
        <argument name="searchRequestName" xsi:type="string">quick_search_container</argument>

So we need to write virtualType class Instead of direct Magento search collection, like

<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="YOUR_COMPANY_NAME\YOUR_MODULE_NAME\Model\ResourceModel\Fulltext\Collection" />
  • Hi @KeyurShah I had face same issue and M233 EE and same solution added but not working? Do you know why? – Rohan Hapani Jan 29 '20 at 12:32
  • To be honest, I did not test with M233 EE, but it should work. after changing the di.xml did you remove generation directory? and run the di:compile command? @RohanHapani – Keyur Shah Jan 29 '20 at 12:45
  • Yes. Already did. But, still no any result. – Rohan Hapani Jan 29 '20 at 12:56
  • This class file called instead of custom : Magento\CatalogStaging\Model\ResourceModel\Fulltext\Collection\Interceptor – Rohan Hapani Jan 29 '20 at 13:08
  • Need to check this, but are you sure that this class also has VirtualType? – Keyur Shah Jan 29 '20 at 13:25

I test this code it is working for me file location etc/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection" type="Spacename\Moduelname\Model\Rewrite\ResourceModel\Fulltext\Collection" />

Check if you missed something else.

  • Thanks for the answer, I tried the same thing that It is seems not working for me ? (: – Keyur Shah Apr 4 '17 at 12:41
  • @KeyurShah i think problem with you di.xml can you share the complete file also tell me is your module listed in admin? – Qaisar Satti Apr 4 '17 at 12:44
  • I am using this in frontend. And check my edits @Qaisar – Keyur Shah Apr 4 '17 at 12:49
  • @KeyurShah what is your class path it must be Accenture\Product\Model\ResourceModel\Fulltext\CatalogSearch\Collection.php also don't understand the frontend are you using etc/frontend/di.xml? – Qaisar Satti Apr 4 '17 at 12:52
  • Yes, just changed the path, still no luck,and I am using this file for frontend only. @Qaisar – Keyur Shah Apr 4 '17 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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