Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] #18956 Fixes for set root_category_id #19237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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