Skip to content

Commit

Permalink
ENGCOM-3480: [Forwardport] #18956 Fixes for set root_category_id #19237
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
magento-engcom-team committed Nov 16, 2018
2 parents e6fee77 + 7be21e2 commit f1b25b9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 31 deletions.
20 changes: 10 additions & 10 deletions app/code/Magento/Store/Model/Config/Importer/Processor/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

/**
* The processor for creating of new entities.
*
* {@inheritdoc}
*/
class Create implements ProcessorInterface
{
Expand Down Expand Up @@ -84,7 +82,9 @@ public function __construct(
/**
* Creates entities in application according to the data set.
*
* {@inheritdoc}
* @param array $data The data to be processed
* @return void
* @throws RuntimeException If processor was unable to finish execution
*/
public function run(array $data)
{
Expand Down Expand Up @@ -176,8 +176,11 @@ private function createGroups(array $items, array $data)
);

$group = $this->groupFactory->create();
if (!isset($groupData['root_category_id'])) {
$groupData['root_category_id'] = 0;
}

$group->setData($groupData);
$group->setRootCategoryId(0);

$group->getResource()->save($group);
$group->getResource()->addCommitCallback(function () use ($data, $group, $website) {
Expand Down Expand Up @@ -226,8 +229,7 @@ private function createStores(array $items, array $data)
}

/**
* Searches through given websites and compares with current websites.
* Returns found website.
* Searches through given websites and compares with current websites and returns found website.
*
* @param array $data The data to be searched in
* @param string $websiteId The website id
Expand All @@ -249,8 +251,7 @@ private function detectWebsiteById(array $data, $websiteId)
}

/**
* Searches through given groups and compares with current websites.
* Returns found group.
* Searches through given groups and compares with current websites and returns found group.
*
* @param array $data The data to be searched in
* @param string $groupId The group id
Expand All @@ -272,8 +273,7 @@ private function detectGroupById(array $data, $groupId)
}

/**
* Searches through given stores and compares with current stores.
* Returns found store.
* Searches through given stores and compares with current stores and returns found store.
*
* @param array $data The data to be searched in
* @param string $storeId The store id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,30 @@ private function initTestData()
'root_category_id' => '1',
'default_store_id' => '1',
'code' => 'default',
],
2 => [
'group_id' => '1',
'website_id' => '1',
'name' => 'Default1',
'default_store_id' => '1',
'code' => 'default1',
]
];
$this->trimmedGroup = [
'name' => 'Default',
'root_category_id' => '1',
'code' => 'default',
'default_store_id' => '1',
];
$this->trimmedGroup =
[
0 => [
'name' => 'Default',
'root_category_id' => '1',
'code' => 'default',
'default_store_id' => '1',
],
1 => [
'name' => 'Default1',
'root_category_id' => '0',
'code' => 'default1',
'default_store_id' => '1'
]
];
$this->stores = [
'default' => [
'store_id' => '1',
Expand Down Expand Up @@ -280,46 +296,46 @@ public function testRunGroup()
[ScopeInterface::SCOPE_GROUPS, $this->groups, $this->groups],
]);

$this->websiteMock->expects($this->once())
$this->websiteMock->expects($this->exactly(2))
->method('getResource')
->willReturn($this->abstractDbMock);

$this->groupMock->expects($this->once())
$this->groupMock->expects($this->exactly(2))
->method('setData')
->with($this->trimmedGroup)
->willReturnSelf();
$this->groupMock->expects($this->exactly(3))
->withConsecutive(
[$this->equalTo($this->trimmedGroup[0])],
[$this->equalTo($this->trimmedGroup[1])]
)->willReturnSelf();

$this->groupMock->expects($this->exactly(6))
->method('getResource')
->willReturn($this->abstractDbMock);
$this->groupMock->expects($this->once())
->method('setRootCategoryId')
->with(0);
$this->groupMock->expects($this->once())
$this->groupMock->expects($this->exactly(2))
->method('getDefaultStoreId')
->willReturn($defaultStoreId);
$this->groupMock->expects($this->once())
$this->groupMock->expects($this->exactly(2))
->method('setDefaultStoreId')
->with($storeId);
$this->groupMock->expects($this->once())
$this->groupMock->expects($this->exactly(2))
->method('setWebsite')
->with($this->websiteMock);

$this->storeMock->expects($this->once())
$this->storeMock->expects($this->exactly(2))
->method('getResource')
->willReturn($this->abstractDbMock);
$this->storeMock->expects($this->once())
$this->storeMock->expects($this->exactly(2))
->method('getStoreId')
->willReturn($storeId);

$this->abstractDbMock->expects($this->any())
->method('load')
->withConsecutive([$this->websiteMock, 'base', 'code'], [$this->storeMock, 'default', 'code'])
->willReturnSelf();
$this->abstractDbMock->expects($this->exactly(2))
$this->abstractDbMock->expects($this->exactly(4))
->method('save')
->with($this->groupMock)
->willReturnSelf();
$this->abstractDbMock->expects($this->once())
$this->abstractDbMock->expects($this->exactly(2))
->method('addCommitCallback')
->willReturnCallback(function ($function) {
return $function();
Expand Down

0 comments on commit f1b25b9

Please sign in to comment.