Magento 2: Category Pages from Page 2 shows without products always
-
17-03-2021 - |
Question
I'm trying to migrate a Magento 1.9.3.6
to Magento 2.3
and I found a strange problem. I've got some categories with thousands of products, I can see 64 products in my first page or 16, but if I go to page 2 http://v2.dendago.eus/moda?p=2
it says that there is no product. In any category happens the same. I've re-indexed and cleaned cache multiple times.
Any advice?
Solution
Look at the file vendor\magento\module-elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier.php
Find apply()
method and replace it with the below function.
Magento recently introduced hotfix by adding $this->collection->setPageSize(null);
to the SearchResultApplier.php
class.
public function apply()
{
if (empty($this->searchResult->getItems())) {
$this->collection->getSelect()->where('NULL');
return;
}
$ids = [];
foreach ($this->searchResult->getItems() as $item) {
$ids[] = (int)$item->getId();
}
$this->collection->setPageSize(null);
$this->collection->getSelect()->where('e.entity_id IN (?)', $ids);
$orderList = join(',', $ids);
$this->collection->getSelect()->reset(\Magento\Framework\DB\Select::ORDER);
$this->collection->getSelect()->order("FIELD(e.entity_id,$orderList)");
}
Add a plugin on above class.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange