Skip to content

Commit 1b39196

Browse files
fix store website name rewrites
1 parent 6d15bb1 commit 1b39196

File tree

2 files changed

+131
-16
lines changed
  • app/code/Magento/Store/Ui/Component/Listing/Column/Store
  • dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store

2 files changed

+131
-16
lines changed

app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Store\Model\System\Store as SystemStore;
1111

1212
/**
13-
* Class Options
13+
* Ui stores options
1414
*/
1515
class Options implements OptionSourceInterface
1616
{
@@ -93,37 +93,38 @@ protected function sanitizeName($name)
9393
*
9494
* @return void
9595
*/
96-
protected function generateCurrentOptions()
96+
protected function generateCurrentOptions(): void
9797
{
9898
$websiteCollection = $this->systemStore->getWebsiteCollection();
9999
$groupCollection = $this->systemStore->getGroupCollection();
100100
$storeCollection = $this->systemStore->getStoreCollection();
101-
/** @var \Magento\Store\Model\Website $website */
101+
102102
foreach ($websiteCollection as $website) {
103103
$groups = [];
104-
/** @var \Magento\Store\Model\Group $group */
105104
foreach ($groupCollection as $group) {
106-
if ($group->getWebsiteId() == $website->getId()) {
105+
if ($group->getWebsiteId() === $website->getId()) {
107106
$stores = [];
108-
/** @var \Magento\Store\Model\Store $store */
109107
foreach ($storeCollection as $store) {
110-
if ($store->getGroupId() == $group->getId()) {
111-
$name = $this->sanitizeName($store->getName());
112-
$stores[$name]['label'] = str_repeat(' ', 8) . $name;
113-
$stores[$name]['value'] = $store->getId();
108+
if ($store->getGroupId() === $group->getId()) {
109+
$stores[] = [
110+
'label' => str_repeat(' ', 8) . $this->sanitizeName($store->getName()),
111+
'value' => $store->getId(),
112+
];
114113
}
115114
}
116115
if (!empty($stores)) {
117-
$name = $this->sanitizeName($group->getName());
118-
$groups[$name]['label'] = str_repeat(' ', 4) . $name;
119-
$groups[$name]['value'] = array_values($stores);
116+
$groups[] = [
117+
'label' => str_repeat(' ', 4) . $this->sanitizeName($group->getName()),
118+
'value' => array_values($stores),
119+
];
120120
}
121121
}
122122
}
123123
if (!empty($groups)) {
124-
$name = $this->sanitizeName($website->getName());
125-
$this->currentOptions[$name]['label'] = $name;
126-
$this->currentOptions[$name]['value'] = array_values($groups);
124+
$this->currentOptions[] = [
125+
'label' => $this->sanitizeName($website->getName()),
126+
'value' => array_values($groups),
127+
];
127128
}
128129
}
129130
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Store\Ui\Component\Listing\Column\Store;
9+
10+
use Magento\Store\Model\ResourceModel\Group as GroupResource;
11+
use Magento\Store\Model\ResourceModel\Store as StoreResource;
12+
use Magento\Store\Model\ResourceModel\Website as WebsiteResource;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Test for \Magento\Store\Ui\Component\Listing\Column\Store\Options.
19+
*/
20+
class OptionsTest extends TestCase
21+
{
22+
private const DEFAULT_WEBSITE_NAME = 'Main Website';
23+
private const DEFAULT_STORE_GROUP_NAME = 'Main Website Store';
24+
private const DEFAULT_STORE_NAME = 'Default Store View';
25+
26+
/**
27+
* @var OptionsFactory
28+
*/
29+
private $modelFactory;
30+
31+
/**
32+
* @var StoreManagerInterface
33+
*/
34+
private $storeManager;
35+
36+
/**
37+
* @var WebsiteResource
38+
*/
39+
private $websiteResource;
40+
41+
/**
42+
* @var StoreResource
43+
*/
44+
private $storeResource;
45+
46+
/**
47+
* @var GroupResource
48+
*/
49+
private $groupResource;
50+
51+
/**
52+
* @return void
53+
*/
54+
protected function setUp(): void
55+
{
56+
$objectManager = Bootstrap::getObjectManager();
57+
58+
$this->modelFactory = $objectManager->get(OptionsFactory::class);
59+
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
60+
61+
$this->websiteResource = $objectManager->get(WebsiteResource::class);
62+
$this->groupResource = $objectManager->get(GroupResource::class);
63+
$this->storeResource = $objectManager->get(StoreResource::class);
64+
}
65+
66+
/**
67+
* To option array test with duplicate website, store group, store view names
68+
*
69+
* @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
70+
*
71+
* @return void
72+
*/
73+
public function testToOptionArray(): void
74+
{
75+
$website = $this->storeManager->getWebsite('test');
76+
$this->websiteResource->save($website->setName(self::DEFAULT_WEBSITE_NAME));
77+
78+
$storeGroup = current($website->getGroups());
79+
$this->groupResource->save($storeGroup->setName(self::DEFAULT_STORE_GROUP_NAME));
80+
81+
$store = current($website->getStores());
82+
$this->storeResource->save($store->setName(self::DEFAULT_STORE_NAME));
83+
84+
$model = $this->modelFactory->create();
85+
$storeIds = [$this->storeManager->getStore('default')->getId(), $store->getId()];
86+
87+
$this->assertEquals($this->getExpectedOptions($storeIds), $model->toOptionArray());
88+
}
89+
90+
/**
91+
* Returns expected options
92+
*
93+
* @param array $storeIds
94+
* @return array
95+
*/
96+
private function getExpectedOptions(array $storeIds): array
97+
{
98+
$expectedOptions = [];
99+
foreach ($storeIds as $storeId) {
100+
$expectedOptions[] = [
101+
'label' => self::DEFAULT_WEBSITE_NAME,
102+
'value' => [[
103+
'label' => str_repeat(' ', 4) . self::DEFAULT_STORE_GROUP_NAME,
104+
'value' => [[
105+
'label' => str_repeat(' ', 8) . self::DEFAULT_STORE_NAME,
106+
'value' => $storeId,
107+
]],
108+
]],
109+
];
110+
}
111+
112+
return $expectedOptions;
113+
}
114+
}

0 commit comments

Comments
 (0)