Skip to content

Commit 9e5b41b

Browse files
authored
Merge pull request #209 from magento-cia/AC-5933
AC-5933 Magento Admin stores functionality improvements
2 parents 0e82160 + dc07ec7 commit 9e5b41b

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\Block\System\Store\Grid\Render;
77

8+
use Magento\Framework\DataObject;
9+
810
/**
911
* Store render group
1012
*
@@ -13,9 +15,9 @@
1315
class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1416
{
1517
/**
16-
* {@inheritdoc}
18+
* @inheritDoc
1719
*/
18-
public function render(\Magento\Framework\DataObject $row)
20+
public function render(DataObject $row): ?string
1921
{
2022
if (!$row->getData($this->getColumn()->getIndex())) {
2123
return null;
@@ -28,6 +30,6 @@ public function render(\Magento\Framework\DataObject $row)
2830
'">' .
2931
$this->escapeHtml($row->getData($this->getColumn()->getIndex())) .
3032
'</a><br />'
31-
. '(' . __('Code') . ': ' . $row->getGroupCode() . ')';
33+
. '(' . __('Code') . ': ' . $this->escapeHtml($row->getGroupCode()) . ')';
3234
}
3335
}

app/code/Magento/Store/Model/Group.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
*/
1010
namespace Magento\Store\Model;
1111

12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
14+
use Magento\Store\Model\Validation\StoreValidator;
15+
1216
/**
13-
* Class Group
17+
* Store Group model class used to retrieve and format group information
1418
*
1519
* @api
1620
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -21,9 +25,9 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
2125
\Magento\Store\Api\Data\GroupInterface,
2226
\Magento\Framework\App\ScopeInterface
2327
{
24-
const ENTITY = 'store_group';
28+
public const ENTITY = 'store_group';
2529

26-
const CACHE_TAG = 'store_group';
30+
public const CACHE_TAG = 'store_group';
2731

2832
/**
2933
* @var bool
@@ -101,10 +105,15 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
101105
private $eventManager;
102106

103107
/**
104-
* @var \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface
108+
* @var PoisonPillPutInterface
105109
*/
106110
private $pillPut;
107111

112+
/**
113+
* @var StoreValidator
114+
*/
115+
private $modelValidator;
116+
108117
/**
109118
* @param \Magento\Framework\Model\Context $context
110119
* @param \Magento\Framework\Registry $registry
@@ -117,7 +126,8 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
117126
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
118127
* @param array $data
119128
* @param \Magento\Framework\Event\ManagerInterface|null $eventManager
120-
* @param \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface|null $pillPut
129+
* @param PoisonPillPutInterface|null $pillPut
130+
* @param StoreValidator|null $modelValidator
121131
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
122132
*/
123133
public function __construct(
@@ -132,15 +142,18 @@ public function __construct(
132142
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
133143
array $data = [],
134144
\Magento\Framework\Event\ManagerInterface $eventManager = null,
135-
\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null
145+
PoisonPillPutInterface $pillPut = null,
146+
StoreValidator $modelValidator = null
136147
) {
137148
$this->_configDataResource = $configDataResource;
138149
$this->_storeListFactory = $storeListFactory;
139150
$this->_storeManager = $storeManager;
140151
$this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance()
141152
->get(\Magento\Framework\Event\ManagerInterface::class);
142153
$this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance()
143-
->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class);
154+
->get(PoisonPillPutInterface::class);
155+
$this->modelValidator = $modelValidator ?: ObjectManager::getInstance()
156+
->get(StoreValidator::class);
144157
parent::__construct(
145158
$context,
146159
$registry,
@@ -162,6 +175,17 @@ protected function _construct()
162175
$this->_init(\Magento\Store\Model\ResourceModel\Group::class);
163176
}
164177

178+
/**
179+
* Validation rules for store
180+
*
181+
* @return \Zend_Validate_Interface|null
182+
* @throws \Zend_Validate_Exception
183+
*/
184+
protected function _getValidationRulesBeforeSave(): ?\Zend_Validate_Interface
185+
{
186+
return $this->modelValidator;
187+
}
188+
165189
/**
166190
* Load store collection and set internal data
167191
*

dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ProductAttributesCleanUpTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private function prepareAdditionalStore()
104104
$storeGroup = $this->objectManager->create(\Magento\Store\Model\Group::class);
105105
$storeGroup->setWebsiteId($website->getId());
106106
$storeGroup->setName('Fixture Store Group');
107+
$storeGroup->setCode('fixturestoregroup');
107108
$storeGroup->setRootCategoryId(2);
108109
$storeGroup->setDefaultStoreId($store->getId());
109110
$storeGroup->save();

dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* Copyright © Magento, Inc. All rights reserved.
45
* See COPYING.txt for license details.
56
*/
6-
declare(strict_types=1);
77

88
namespace Magento\Catalog\Model\Indexer\Product\Flat;
99

@@ -17,6 +17,7 @@
1717

1818
/**
1919
* Integration tests for \Magento\Catalog\Model\Indexer\Product\Flat\Processor.
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2021
*/
2122
class ProcessorTest extends TestCase
2223
{
@@ -145,7 +146,13 @@ public function testAddNewStoreGroup(): void
145146
\Magento\Store\Model\Group::class
146147
);
147148
$storeGroup->setData(
148-
['website_id' => 1, 'name' => 'New Store Group', 'root_category_id' => 2, 'group_id' => null]
149+
[
150+
'website_id' => 1,
151+
'name' => 'New Store Group',
152+
'root_category_id' => 2,
153+
'group_id' => null,
154+
'code' => 'newstoregroup'
155+
]
149156
);
150157
$storeGroup->save();
151158
$this->assertTrue($this->processor->getIndexer()->isInvalid());

0 commit comments

Comments
 (0)