Skip to content

Commit a89f35d

Browse files
committed
Merge remote-tracking branch 'origin/MC-36652' into 2.4-develop-pr38
2 parents b3ad364 + 597d072 commit a89f35d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/code/Magento/Reports/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Reports\Model\ResourceModel\Quote\Item;
89

@@ -17,6 +18,8 @@
1718
*/
1819
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
1920
{
21+
private const PREPARED_FLAG_NAME = 'reports_collection_prepared';
22+
2023
/**
2124
* Join fields
2225
*
@@ -99,6 +102,11 @@ protected function _construct()
99102
public function prepareActiveCartItems()
100103
{
101104
$quoteItemsSelect = $this->getSelect();
105+
106+
if ($this->getFlag(self::PREPARED_FLAG_NAME)) {
107+
return $quoteItemsSelect;
108+
}
109+
102110
$quoteItemsSelect->reset()
103111
->from(['main_table' => $this->getTable('quote_item')], '')
104112
->columns('main_table.product_id')
@@ -114,6 +122,7 @@ public function prepareActiveCartItems()
114122
)->group(
115123
'main_table.product_id'
116124
);
125+
$this->setFlag(self::PREPARED_FLAG_NAME, true);
117126

118127
return $quoteItemsSelect;
119128
}

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/Quote/CollectionTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Event\ManagerInterface;
1616
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1717
use Magento\Quote\Model\ResourceModel\Quote;
18+
use Magento\Reports\Model\ResourceModel\Quote\Collection;
1819
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021

@@ -42,7 +43,7 @@ protected function setUp(): void
4243
public function testGetSelectCountSql()
4344
{
4445
/** @var MockObject $collection */
45-
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Collection::class)
46+
$collection = $this->getMockBuilder(Collection::class)
4647
->setMethods(['getSelect'])
4748
->disableOriginalConstructor()
4849
->getMock();
@@ -62,20 +63,25 @@ public function testPrepareActiveCartItems()
6263
$constructArgs = $this->objectManager
6364
->getConstructArguments(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class);
6465
$collection = $this->getMockBuilder(\Magento\Reports\Model\ResourceModel\Quote\Item\Collection::class)
65-
->setMethods(['getSelect', 'getTable'])
66+
->setMethods(['getSelect', 'getTable', 'getFlag', 'setFlag'])
6667
->disableOriginalConstructor()
6768
->setConstructorArgs($constructArgs)
6869
->getMock();
6970

70-
$collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock);
71+
$collection->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock);
7172
$this->selectMock->expects($this->once())->method('reset')->willReturnSelf();
7273
$this->selectMock->expects($this->once())->method('from')->willReturnSelf();
7374
$this->selectMock->expects($this->atLeastOnce())->method('columns')->willReturnSelf();
7475
$this->selectMock->expects($this->once())->method('joinInner')->willReturnSelf();
7576
$this->selectMock->expects($this->once())->method('where')->willReturnSelf();
7677
$this->selectMock->expects($this->once())->method('group')->willReturnSelf();
7778
$collection->expects($this->exactly(2))->method('getTable')->willReturn('table');
79+
$collection->expects($this->once())->method('setFlag')
80+
->with('reports_collection_prepared')->willReturnSelf();
7881
$collection->prepareActiveCartItems();
82+
$collection->method('getFlag')
83+
->with('reports_collection_prepared')->willReturn(true);
84+
$this->assertEquals($this->selectMock, $collection->prepareActiveCartItems());
7985
}
8086

8187
public function testLoadWithFilter()

0 commit comments

Comments
 (0)