File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
app/code/Magento/Ui/Model/Export Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments