Skip to content

Fulltext collection used on category page in toolbar pager links #9807

@daniel-ifrim

Description

@daniel-ifrim

Preconditions

  1. 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

  1. On category page, in class \Magento\Catalog\Block\Product\ProductList\Toolbar::getPagerHtml() function the collection in use is \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection
  2. Log the collection query with $this->getCollection()->getSelect()->__toString()
  3. The query does an extra JOIN:
    INNER JOIN search_tmp_592dad48d1e409_82724533 AS search_result ON 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

  1. 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.
#9807issue

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogIssue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentbug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions