Skip to content

Commit 3e64cb2

Browse files
AC-9607::Filtering Company Grid & Then Attempting Grid CSV Export Will Fail & Throw Exception
1 parent 6f4805f commit 3e64cb2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

app/code/Magento/Ui/Model/Export/ConvertToCsv.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,30 @@ public function getCsvFile()
8181
$searchCriteria = $dataProvider->getSearchCriteria()
8282
->setCurrentPage($i)
8383
->setPageSize($this->pageSize);
84-
$totalCount = (int) $dataProvider->getSearchResult()->getTotalCount();
85-
$totalPagesCount = (int) ceil($totalCount / $this->pageSize);
86-
while ($i <= $totalPagesCount) {
87-
// setTotalCount to prevent total count from being calculated in loop
84+
85+
$totalCount = null;
86+
$totalPagesCount = null;
87+
88+
do {
8889
$searchResult = $dataProvider->getSearchResult();
89-
$searchResult->setTotalCount($totalCount);
9090
$items = $searchResult->getItems();
91+
92+
if ($totalCount === null) { // get total count only once
93+
$totalCount = $searchResult->getTotalCount();
94+
$totalPagesCount = (int) ceil($totalCount / $this->pageSize);
95+
}
96+
97+
// call setTotalCount to prevent total count from being calculate in subsequent iterations of this loop
98+
$searchResult->setTotalCount($totalCount);
99+
91100
foreach ($items as $item) {
92101
$this->metadataProvider->convertDate($item, $component->getName());
93102
$stream->writeCsv($this->metadataProvider->getRowData($item, $fields, $options));
94103
}
104+
95105
$searchCriteria->setCurrentPage(++$i);
96-
}
106+
} while ($i <= $totalPagesCount);
107+
97108
$stream->unlock();
98109
$stream->close();
99110

0 commit comments

Comments
 (0)