Skip to content

Commit 2038d7d

Browse files
author
Sergey Nezbritskiy
committed
Flush totalRecords when clearing data collection
1 parent e457037 commit 2038d7d

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType =
395395

396396
if (!empty($conditionSql)) {
397397
$this->getSelect()->where($conditionSql, null, \Magento\Framework\DB\Select::TYPE_CONDITION);
398-
$this->invalidateSize();
398+
$this->_totalRecords = null;
399399
} else {
400400
throw new \Magento\Framework\Exception\LocalizedException(
401401
__('Invalid attribute identifier for filter (%1)', get_class($attribute))
@@ -1720,15 +1720,4 @@ public function removeAllFieldsFromSelect()
17201720
return $this->removeAttributeToSelect();
17211721
}
17221722

1723-
/**
1724-
* Invalidates "Total Records Count".
1725-
* Invalidates saved "Total Records Count" attribute with last counting,
1726-
* so a next calling of method getSize() will query new total records count.
1727-
*
1728-
* @return void
1729-
*/
1730-
private function invalidateSize(): void
1731-
{
1732-
$this->_totalRecords = null;
1733-
}
17341723
}

dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/CartTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,4 @@ public function testToHtmlCartItem()
100100
$this->assertContains('$10.00', $html);
101101
$this->assertContains('catalog/product/edit/id/1', $html);
102102
}
103-
104-
/**
105-
* Verify that the customer has a single item in his cart.
106-
*
107-
* @magentoDataFixture Magento/Customer/_files/customer.php
108-
* @magentoDataFixture Magento/Customer/_files/quote.php
109-
*/
110-
public function testGetCollection()
111-
{
112-
$this->assertEquals(1, $this->block->getCollection()->getSize());
113-
}
114103
}

lib/internal/Magento/Framework/Data/Collection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ public function clear()
492492
{
493493
$this->_setIsLoaded(false);
494494
$this->_items = [];
495+
$this->_totalRecords = null;
495496
return $this;
496497
}
497498

lib/internal/Magento/Framework/Test/Unit/Data/CollectionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ public function testWalk()
5757
);
5858
}
5959

60+
/**
61+
* Ensure that getSize works correctly with clear
62+
*
63+
*/
64+
public function testClearTotalRecords()
65+
{
66+
$objOne = new \Magento\Framework\DataObject(['id' => 1, 'name' => 'one']);
67+
$objTwo = new \Magento\Framework\DataObject(['id' => 2, 'name' => 'two']);
68+
$objThree = new \Magento\Framework\DataObject(['id' => 3, 'name' => 'three']);
69+
70+
/** @noinspection PhpUnhandledExceptionInspection */
71+
$this->collection->addItem($objOne);
72+
/** @noinspection PhpUnhandledExceptionInspection */
73+
$this->collection->addItem($objTwo);
74+
/** @noinspection PhpUnhandledExceptionInspection */
75+
$this->collection->addItem($objThree);
76+
$this->assertEquals(3, $this->collection->getSize());
77+
$this->collection->clear();
78+
$this->assertEquals(0, $this->collection->getSize());
79+
}
80+
6081
/**
6182
* Callback function.
6283
*

0 commit comments

Comments
 (0)