4

a similar problem. If i want filter product collection, create plugin for Layer (if use event the result will be the same).

enter image description here

enter image description here

The collection is correct and show only 2 products. But the Pagination order Category Filter show 9 Products.

Why??

0

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;

0

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.

0

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

  • No i want to filter by a custom product attribut not by category. – Ehrling Jan 3 '17 at 10:00
  • im using Magento 2.1.3. Not working... – Ehrling Jan 3 '17 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.