I'm trying to find the portion of code where the filters from the layered navigation are applied to the product collection.
The method called for product collection retrival is Magento\Catalog\Block\Product\ListProduct::_getProductCollection
Which in turn calls Magento\Catalog\Model\Layer::getProductCollection
this uses a collection provider
to instantiate the collection and then Magento\Catalog\Model\Layer::prepareProductCollection()
.
The layer object above contains the filters selected in the layered navigation on frontend and above metioned function (prepare) uses Magento\Catalog\Model\Layer\Category\CollectionFilter::filter
.
As stated in the function associated comment this should filter the collection * Filter product collection
yet I see no filters from the layered navigation applied.
I still can not find where the filters from the layered navigation are applied.
I should mention that the Magento\Catalog\Block\Product\ListProduct::_getProductCollection
is called in the Magento\Catalog\Block\Product\ListProduct::_beforeToHtml
method at then end of this method the filtered collection is loaded but even going with the debugger line by line I still can not find the portion of code that applies the filters.
In this method an 'catalog_block_product_list_collection'
event is dispatched. Is it possible that the filters are applied in an Observer?
EDIT:
The only observer tapped to this event is Magento\Review\Observer\CatalogBlockProductCollectionBeforeToHtmlObserver
and it does not seem to be related to my problem.
Edit 2:
The product collection used in Magento\Catalog\Block\Product\LitProduct
is extended from Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection
which has a method _renderFiltersBefore
which is called when the collection is loaded. Here the filters are fed and set through a searchCriteriaBuilder
the search is made and put in a temporary table which is joined with the productCollection.
I still can not find the actual piece of code that retrieves and handles the filters.
Any help is appreciated.
Many thanks.