Skip to content

Commit b202840

Browse files
committed
Abandoned cart report generate duplicate records
1 parent 81340cb commit b202840

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Extended.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
8787
protected $_massactionIdFilter;
8888

8989
/**
90-
* Massaction block name
91-
*
9290
* @var string
9391
*/
9492
protected $_massactionBlockName = \Magento\Backend\Block\Widget\Grid\Massaction\Extended::class;
@@ -122,8 +120,6 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
122120
protected $_headersVisibility = true;
123121

124122
/**
125-
* Filter visibility
126-
*
127123
* @var boolean
128124
*/
129125
protected $_filterVisibility = true;
@@ -148,15 +144,11 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
148144
protected $_isCollapsed;
149145

150146
/**
151-
* Count subtotals
152-
*
153147
* @var boolean
154148
*/
155149
protected $_countSubTotals = false;
156150

157151
/**
158-
* SubTotals
159-
*
160152
* @var \Magento\Framework\DataObject[]
161153
*/
162154
protected $_subtotals = [];
@@ -964,6 +956,7 @@ public function _exportIterateCollection($callback, array $args)
964956

965957
while ($break !== true) {
966958
$collection = clone $originalCollection;
959+
$collection->clear();
967960
$collection->setPageSize($this->_exportPageSize);
968961
$collection->setCurPage($page);
969962
$collection->load();
@@ -975,7 +968,6 @@ public function _exportIterateCollection($callback, array $args)
975968
$break = true;
976969
}
977970
$page++;
978-
979971
foreach ($collection as $item) {
980972
//phpcs:ignore Magento2.Functions.DiscouragedFunction
981973
call_user_func_array(

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,22 @@ public function resolveCustomerNames()
200200
foreach ($this->getItems() as $item) {
201201
foreach ($customersData as $customerItemData) {
202202
if ($item['customer_id'] == $customerItemData['entity_id']) {
203-
$item->setData(array_merge($item->getData(), $customerItemData));
203+
$item['customer_name'] = $customerItemData['customer_name'];
204+
$item['email'] = $customerItemData['email'];
205+
$item->setData($item->getData());
204206
}
205207
}
206208
}
207209
}
210+
211+
/**
212+
* Append customer data after collection load
213+
*
214+
* @return Collection|void
215+
*/
216+
protected function _afterLoad()
217+
{
218+
parent::_afterLoad();
219+
$this->resolveCustomerNames();
220+
}
208221
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,41 +131,41 @@ public function testResolveCustomerNames()
131131
$this->selectMock->expects($this->any())
132132
->method('getConnection')
133133
->willReturn($this->connectionMock);
134-
$this->selectMock->expects($this->once())
134+
$this->selectMock->expects($this->atLeastOnce())
135135
->method('from')
136136
->with(['customer' => $customerTableName], ['entity_id', 'email'])
137137
->willReturnSelf();
138-
$this->selectMock->expects($this->once())
138+
$this->selectMock->expects($this->atLeastOnce())
139139
->method('columns')
140140
->with(['customer_name' => $customerName])
141141
->willReturnSelf();
142-
$this->selectMock->expects($this->once())
142+
$this->selectMock->expects($this->atLeastOnce())
143143
->method('where')
144144
->with('customer.entity_id IN (?)')
145145
->willReturnSelf();
146146

147-
$this->connectionMock->expects($this->once())
147+
$this->connectionMock->expects($this->atLeastOnce())
148148
->method('getConcatSql')
149149
->with(['firstname', 'lastname'], ' ')
150150
->willReturn($customerName);
151151

152152
$this->customerResourceMock->expects($this->any())
153153
->method('getConnection')
154154
->willReturn($this->connectionMock);
155-
$this->customerResourceMock->expects($this->once())
155+
$this->customerResourceMock->expects($this->atLeastOnce())
156156
->method('getTable')
157157
->with('customer_entity')
158158
->willReturn($customerTableName);
159159

160160
$this->connectionMock->expects($this->any())
161161
->method('select')
162162
->willReturn($this->selectMock);
163-
$this->connectionMock->expects($this->once())
163+
$this->connectionMock->expects($this->atLeastOnce())
164164
->method('fetchAll')
165165
->with($this->selectMock)
166166
->willReturn($customersData);
167167

168-
$this->fetchStrategyMock->expects($this->once())
168+
$this->fetchStrategyMock->expects($this->atLeastOnce())
169169
->method('fetchAll')
170170
->withAnyParameters()
171171
->willReturn($customerId);

0 commit comments

Comments
 (0)