-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to override Fulltext\Collection in module et/di.xml #7734
Comments
Hi, Thanks for reporting this issue. We've created internal ticket MAGETWO-64162 to address this issue. The reason why it doesn’t work now is because the class In Magento 2.1.3. I can find only one virtual type for the class <virtualType name="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection">
<arguments>
<argument name="searchRequestName" xsi:type="string">quick_search_container</argument>
</arguments>
</virtualType> So to resolve your problem you may define preference for the virtual type: <preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollection" type="Sanimarkt\App\Model\ResourceModel\Fulltext\Collection" /> |
Hi @joachimVT , Could you please provide a bit more details why do you need to extend search Collection? This happens because of the Search Collection design. That's why it's better to leave \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection as is, and customize its behavior with other mechanism. We could advise you how to better solve your specific task if you will shed some light and provide more details. |
I don't understand, It is bug or feature? ) |
In the comment you mentioned, @kandy talking about an ability to use plugins with virtual types and that's another issue. I'm not sure is it fixed or not, but that's not the same issue as this one. |
@igrybkov, great comment, thank you for the clarification!
Now that's something that should be put into the devdocs for good. |
@korostii, probably it should be documented as an answer to the question "how to override virtual type" or even "what to do when I want to override a class which is used as virtual type", but in general, as @maghamed said, Magento discouraging inheritance, and for each specific case it's better to find the way how to customize behavior using plugins and specific API/SPI or another extension points. |
@igrybkov The reason I want to customize the search engine is to use Logical AND search I know this is possible by using the SEARCH REST API (http://devdocs.magento.com/guides/v2.0/howdoi/webapi/search-criteria.html#logical-and-search) But I wanted this to be possible by searching in the standard search form. |
@igrybkov Thanks for the explanation. Right now I have same requirement (I mean to override search collection, with your comment I can able to override the class), But can;t get any search result. Before overriding I am getting the search result and after overriding I am not getting any search result. Even I tried to search with exact product name but couldn't get any search result. Any comment for this ? Note : I done the di;compile and cache:flush after changes in di.xml. |
@m2developer, it depends on what you changed. Just overriding with inherited class will not affect the behavior of the system in the way you mentioned. I cannot assist you regarding your case here (and the same regarding @joachimVT's case) as GitHub is the place for bug reports, but this case is not a bug, and therefore closed. I'll suggest you ask your question with specific code example in the Community Forums or the Magento Stack Exchange, and post the link here for someone who will look for similar question through GitHub. |
@igrybkov Thanks for quick response. For this I just written the same thing which you have mention, and I don't have any external plugins. Also, I am using Magento 2 EE edition, and I found that module CatalogStaging override this class like
They are not using overriding the class by
Any comment on this ? |
@igrybkov Any comment on this ? |
This is clearly references to the Bugs #9066 and #5590 if not many other tickets here. -Plugins don't work because of a protected method The only thing that worked so far is hacking the core code. But I really don't want to do that. |
There is a solution, that changes to search operand from OR to AND, you need to create a Module for this yourVendor/yourmodule/etc/search_request.xml yourVendor/yourmodule/etc/module.xml yourVendor/yourmodule/registration.php |
Hey, @leedave I would not say that bugs you mentioned are related to Search Customization. Yes, customization of Request.xml is a way to go. But if you see that Magento has flaws in Core implementation of Fulltext Collection and
Maybe it makes sense to fix that in a core and make a Code contribution as Pull Request. |
Hi @maghamed If you agree that there are flaws to fix in the core, would it not make sense to also reopen this issue and mark it as As @orlangur mentioned elsewhere and I tend to agree in principle, providing pull requests for changes which might get rejected - is potentially quite a waste of time. Besides, seeing this issue as "Done" in project "branch [develop]" is really confusing. |
I want to add category filter in catalog search. What do I need to do ? |
Anyone still on this?? I am using elasticsearch(ES) with magento2. As you know ES can set its own order, like order by name or id or something else. Now I am working to get my search results in a better order, which is already realized using ES, but magento2 will never give me the correct order, because in this "Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection", there is a function: "_renderFiltersBefore", and at the last of it, there is:
This caused all my search results disordered. And as I read above posts, I cannot override this "Collection", so does that mean I shouldn't order by search results in ES? That I must use magento to realize any sorting? Why must magento2 set some order if I have already had it done with ES or other search engines? |
@igrybkov What should the I have tried
but I get an Exception:
|
@rparsi |
@developerlicw I want only enabled products in the quick search result. The product boolean attribute I have
Am using magento2 2.2.3 |
@rparsi According to your Exception message, it seems you're still using "status" for query, please check if you have already removed it. |
@developerlicw I did remove it. Here is the full content of my
It's copied from |
@rparsi Sorry for the bad answer just now. It seems that exception is caused by unmatched query fields and mapping fields. Maybe you can check whether you've mapped "status" in your mapping. |
I have no idea how to do that (add a given product field/attribute to the mapping). As I've stated earlier, there's no documentation on this, because magento team thinks developers will magically figure this out without any guidance. |
@rparsi Agreed with that, magento do provide quite little information about elasticsearch. If you want to check your mapping, https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html Besides, it maybe better to access elasticsearch engine and confirm the changes directly, I am using a chrome plugin named "elasticsearch-head" and it's quite useful. Hope these information helpful to you :) |
@developerlicw I'm not using elasticsearch, only MySQL. I don't see anything in admin ui for "filterable in search". The closest is in the product attribute edit form there's an option to enable the This is so frustrating. |
@rparsi Oh, I've always thought of elasticsearch! My apologies for the misunderstanding, cause I'm using elasticsearch... Sorry about being not so helpful, I am also working on magento2, and will inform you if I got some useful clues. |
This isn't working in 2.3.3 as well. |
If you are using elasticsearch you have to set the following preference for virtual type in your custom module's di.xml as elasticsearch overrides the virtualtype SearchCollection
next if you face the following error
|
245 regression issue
Preconditions
Steps to reproduce
Expected result
Actual result
The text was updated successfully, but these errors were encountered: