Skip to content

getSize() of product collection returns incorrect value after applying addAttributeToFilter() #7730

Closed
@heyqule

Description

@heyqule

The pagination became incorrect. For example, The pagination would show 10 page when there are only 3 pages of product on product listing page.

Preconditions

Magento version 2.1.2

Steps to reproduce

  1. Create a frontend plugin for product collection's load function, beforeLoad()
  2. Add a new addAttributeToFitler() to $subject
  3. get the value of getSize()

Expected result

  1. the getSize() should reflect the total in the collection with new attribute filter.

Actual result

  1. the _totalRecords is not correct for filtered collection. getSize() returns incorrect value.

Investigation:
The total records was pulled from a different model. When I added new attribute filter to the collection, it did not update the search criteria in catalogsearch models. Hence, the total records did not represent the total in the collection.

Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection::_renderFiltersBefore()
Line 347: $this->_totalRecords = $this->searchResult->getTotalCount();

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: 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 passedReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions