a similar problem. If i want filter product collection, create plugin for Layer (if use event the result will be the same).
The collection is correct and show only 2 products. But the Pagination order Category Filter show 9 Products.
Why??
a similar problem. If i want filter product collection, create plugin for Layer (if use event the result will be the same).
The collection is correct and show only 2 products. But the Pagination order Category Filter show 9 Products.
Why??
Please use getSize() function on product collection before returning it. It will calculates all mandatory data for layered and toolbar.
$collection->getSize();
Before this line -
return $collection;
It's a Magento default bug, Issue is solved here.
Replace getSize() function code by below code.
public function getSize()
{
$itemCount = count($this->_items);
if ($this->_totalRecords === null || ($itemCount > 0 && $itemCount !== $this->_totalRecords)) {
$sql = $this->getSelectCountSql();
$this->_totalRecords = (int) $this->getConnection()->fetchOne($sql, $this->_bindParams);
}
return (int) $this->_totalRecords;
}
You can fix it by apply given changes to your core file.
Core file Path : vendor/magento/framework/Data/Collection/AbstractDb.php
Note: This is a temporary solution.
I assume that you are using an older version of magento 2.X.
This issue has been resolved at #e012a48..
Need to modify library collection class: lib/internal/Magento/Framework/Data/Collection/AbstractDb.php