-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions
- Magento 2.4-develop with sample data
I'm in a case with a bug that reports one more product in getSize() on product collection. The product collection in fact the fulltext product collection from Magento_Catalog_Search. Why I get one more product in search collection is not relevant. How I get that one more product is the issue.
Steps to reproduce
- On category page, in class \Magento\Catalog\Block\Product\ProductList\Toolbar::getPagerHtml() function the collection in use is \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection
- Log the collection query with $this->getCollection()->getSelect()->__toString()
- The query does an extra JOIN:
INNER JOINsearch_tmp_592dad48d1e409_82724533ASsearch_resultON e.entity_id = search_result.entity_id
It's a temporary MySQL memory table managed from this class:
\Magento\Framework\Search\Adapter\Mysql\TemporaryStorage
This feature is used in Magento_CatalogSearch module which is ok.
But it is used on category page too.
Expected result
- It should use the usual product collection \Magento\Catalog\Model\ResourceModel\Product\Collection
Actual result
It uses \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection and adds an extra INNER JOIN on a memory table created on the fly in category page.

Beside this it may run other unexpected code from Magento_CatalogSearch or Magento_Search module (I don't confirm this).
The problem is when declaring this in Magento_CatalogSearch/etc/di.xml:
<type name="Magento\Catalog\Model\Layer\Category">
<arguments>
<argument name="context" xsi:type="object">Magento\CatalogSearch\Model\Layer\Category\Context</argument>
</arguments>
</type>
where in Magento_Catalog/etc/di.xml there is this declaration:
<type name="Magento\Catalog\Model\Layer\Category">
<arguments>
<argument name="context" xsi:type="object">Magento\Catalog\Model\Layer\Category\Context</argument>
</arguments>
</type>
You can clearly see that the declaration from Magento_CatalogSearch module replaces the one from Magento_Catalog.
By commenting the above argument injection in Magento_CatalogSearch/etc/di.xml,
the collection Fulltext won't be anymore in \Magento\Catalog\Block\Product\ProductList\Toolbar::getPagerHtml(). The additional join on the memory tables is not made anymore. My case is fixed too.
But this is not the fix. It's a proof of what's happening.
The virtual types declared in both catalog and catalog search modules around Catalog Layer classes look good, but the argument injection from above and the logic behind them needs to be improved.