Skip to content

Commit f1b25b9

Browse files
ENGCOM-3480: [Forwardport] #18956 Fixes for set root_category_id #19237
- Merge Pull Request #19237 from gelanivishal/magento2:2.2-develop-PR-port-18958 - Merged commits: 1. aa4abec 2. acefdb3 3. 5866a39 4. fee2712 5. 7be21e2
2 parents e6fee77 + 7be21e2 commit f1b25b9

File tree

2 files changed

+47
-31
lines changed

2 files changed

+47
-31
lines changed

app/code/Magento/Store/Model/Config/Importer/Processor/Create.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
/**
1818
* The processor for creating of new entities.
19-
*
20-
* {@inheritdoc}
2119
*/
2220
class Create implements ProcessorInterface
2321
{
@@ -84,7 +82,9 @@ public function __construct(
8482
/**
8583
* Creates entities in application according to the data set.
8684
*
87-
* {@inheritdoc}
85+
* @param array $data The data to be processed
86+
* @return void
87+
* @throws RuntimeException If processor was unable to finish execution
8888
*/
8989
public function run(array $data)
9090
{
@@ -176,8 +176,11 @@ private function createGroups(array $items, array $data)
176176
);
177177

178178
$group = $this->groupFactory->create();
179+
if (!isset($groupData['root_category_id'])) {
180+
$groupData['root_category_id'] = 0;
181+
}
182+
179183
$group->setData($groupData);
180-
$group->setRootCategoryId(0);
181184

182185
$group->getResource()->save($group);
183186
$group->getResource()->addCommitCallback(function () use ($data, $group, $website) {
@@ -226,8 +229,7 @@ private function createStores(array $items, array $data)
226229
}
227230

228231
/**
229-
* Searches through given websites and compares with current websites.
230-
* Returns found website.
232+
* Searches through given websites and compares with current websites and returns found website.
231233
*
232234
* @param array $data The data to be searched in
233235
* @param string $websiteId The website id
@@ -249,8 +251,7 @@ private function detectWebsiteById(array $data, $websiteId)
249251
}
250252

251253
/**
252-
* Searches through given groups and compares with current websites.
253-
* Returns found group.
254+
* Searches through given groups and compares with current websites and returns found group.
254255
*
255256
* @param array $data The data to be searched in
256257
* @param string $groupId The group id
@@ -272,8 +273,7 @@ private function detectGroupById(array $data, $groupId)
272273
}
273274

274275
/**
275-
* Searches through given stores and compares with current stores.
276-
* Returns found store.
276+
* Searches through given stores and compares with current stores and returns found store.
277277
*
278278
* @param array $data The data to be searched in
279279
* @param string $storeId The store id

app/code/Magento/Store/Test/Unit/Model/Config/Importer/Processor/CreateTest.php

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,30 @@ private function initTestData()
196196
'root_category_id' => '1',
197197
'default_store_id' => '1',
198198
'code' => 'default',
199+
],
200+
2 => [
201+
'group_id' => '1',
202+
'website_id' => '1',
203+
'name' => 'Default1',
204+
'default_store_id' => '1',
205+
'code' => 'default1',
199206
]
200207
];
201-
$this->trimmedGroup = [
202-
'name' => 'Default',
203-
'root_category_id' => '1',
204-
'code' => 'default',
205-
'default_store_id' => '1',
206-
];
208+
$this->trimmedGroup =
209+
[
210+
0 => [
211+
'name' => 'Default',
212+
'root_category_id' => '1',
213+
'code' => 'default',
214+
'default_store_id' => '1',
215+
],
216+
1 => [
217+
'name' => 'Default1',
218+
'root_category_id' => '0',
219+
'code' => 'default1',
220+
'default_store_id' => '1'
221+
]
222+
];
207223
$this->stores = [
208224
'default' => [
209225
'store_id' => '1',
@@ -280,46 +296,46 @@ public function testRunGroup()
280296
[ScopeInterface::SCOPE_GROUPS, $this->groups, $this->groups],
281297
]);
282298

283-
$this->websiteMock->expects($this->once())
299+
$this->websiteMock->expects($this->exactly(2))
284300
->method('getResource')
285301
->willReturn($this->abstractDbMock);
286302

287-
$this->groupMock->expects($this->once())
303+
$this->groupMock->expects($this->exactly(2))
288304
->method('setData')
289-
->with($this->trimmedGroup)
290-
->willReturnSelf();
291-
$this->groupMock->expects($this->exactly(3))
305+
->withConsecutive(
306+
[$this->equalTo($this->trimmedGroup[0])],
307+
[$this->equalTo($this->trimmedGroup[1])]
308+
)->willReturnSelf();
309+
310+
$this->groupMock->expects($this->exactly(6))
292311
->method('getResource')
293312
->willReturn($this->abstractDbMock);
294-
$this->groupMock->expects($this->once())
295-
->method('setRootCategoryId')
296-
->with(0);
297-
$this->groupMock->expects($this->once())
313+
$this->groupMock->expects($this->exactly(2))
298314
->method('getDefaultStoreId')
299315
->willReturn($defaultStoreId);
300-
$this->groupMock->expects($this->once())
316+
$this->groupMock->expects($this->exactly(2))
301317
->method('setDefaultStoreId')
302318
->with($storeId);
303-
$this->groupMock->expects($this->once())
319+
$this->groupMock->expects($this->exactly(2))
304320
->method('setWebsite')
305321
->with($this->websiteMock);
306322

307-
$this->storeMock->expects($this->once())
323+
$this->storeMock->expects($this->exactly(2))
308324
->method('getResource')
309325
->willReturn($this->abstractDbMock);
310-
$this->storeMock->expects($this->once())
326+
$this->storeMock->expects($this->exactly(2))
311327
->method('getStoreId')
312328
->willReturn($storeId);
313329

314330
$this->abstractDbMock->expects($this->any())
315331
->method('load')
316332
->withConsecutive([$this->websiteMock, 'base', 'code'], [$this->storeMock, 'default', 'code'])
317333
->willReturnSelf();
318-
$this->abstractDbMock->expects($this->exactly(2))
334+
$this->abstractDbMock->expects($this->exactly(4))
319335
->method('save')
320336
->with($this->groupMock)
321337
->willReturnSelf();
322-
$this->abstractDbMock->expects($this->once())
338+
$this->abstractDbMock->expects($this->exactly(2))
323339
->method('addCommitCallback')
324340
->willReturnCallback(function ($function) {
325341
return $function();

0 commit comments

Comments
 (0)