From 7b76b658116ce8c24580a8cde5d60afbce86c74a Mon Sep 17 00:00:00 2001 From: venkatashivakumar Date: Wed, 13 Jul 2022 20:34:33 +0530 Subject: [PATCH 01/14] AC-5905: Customer API improvements --- .../Controller/Rest/ValidateCustomerData.php | 56 +++++++++ .../Rest/ValidateCustomerDataTest.php | 115 ++++++++++++++++++ .../Magento/Customer/etc/webapi_rest/di.xml | 3 + 3 files changed, 174 insertions(+) create mode 100644 app/code/Magento/Customer/Plugin/Webapi/Controller/Rest/ValidateCustomerData.php create mode 100644 app/code/Magento/Customer/Test/Unit/Plugin/Webapi/Controller/Rest/ValidateCustomerDataTest.php diff --git a/app/code/Magento/Customer/Plugin/Webapi/Controller/Rest/ValidateCustomerData.php b/app/code/Magento/Customer/Plugin/Webapi/Controller/Rest/ValidateCustomerData.php new file mode 100644 index 0000000000000..ad2d8ed1cf974 --- /dev/null +++ b/app/code/Magento/Customer/Plugin/Webapi/Controller/Rest/ValidateCustomerData.php @@ -0,0 +1,56 @@ +validateInputData($inputData[self:: CUSTOMER_KEY]); + } + return [$inputData, $parameters]; + } + + /** + * Validates InputData + * + * @param array $inputData + * @return array + */ + private function validateInputData(array $inputData): array + { + $result = []; + + $data = array_filter($inputData, function ($k) use (&$result) { + $key = is_string($k) ? strtolower($k) : $k; + return !isset($result[$key]) && ($result[$key] = true); + }, ARRAY_FILTER_USE_KEY); + + return array_map(function ($value) { + return is_array($value) ? $this->validateInputData($value) : $value; + }, $data); + } +} diff --git a/app/code/Magento/Customer/Test/Unit/Plugin/Webapi/Controller/Rest/ValidateCustomerDataTest.php b/app/code/Magento/Customer/Test/Unit/Plugin/Webapi/Controller/Rest/ValidateCustomerDataTest.php new file mode 100644 index 0000000000000..cda66041ab3c5 --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Plugin/Webapi/Controller/Rest/ValidateCustomerDataTest.php @@ -0,0 +1,115 @@ +validateCustomerDataObject = ObjectManager::getInstance()->get(ValidateCustomerData::class); + $this->reflectionObject = new ReflectionClass(get_class($this->validateCustomerDataObject)); + } + + /** + * Test if the customer Info is valid + * + * @param array $customerInfo + * @param array $result + * @dataProvider dataProviderInputData + * @throws Exception + */ + public function testValidateInputData(array $customerInfo, array $result) + { + $this->assertEquals( + $result, + $this->invokeValidateInputData('validateInputData', [$customerInfo]) + ); + } + + /** + * @param string $methodName + * @param array $arguments + * @return mixed + * @throws Exception + */ + private function invokeValidateInputData(string $methodName, array $arguments = []) + { + $validateInputDataMethod = $this->reflectionObject->getMethod($methodName); + $validateInputDataMethod->setAccessible(true); + return $validateInputDataMethod->invokeArgs($this->validateCustomerDataObject, $arguments); + } + + /** + * @return array + */ + public function dataProviderInputData(): array + { + return [ + [ + ['customer' => + [ + 'id' => -1, + 'Id' => 1, + 'name' => + [ + 'firstName' => 'Test', + 'LastName' => 'user' + ], + 'isHavingOwnHouse' => 1, + 'address' => + [ + 'street' => '1st Street', + 'Street' => '3rd Street', + 'city' => 'London' + ], + ] + ], + ['customer' => + [ + 'id' => -1, + 'name' => + [ + 'firstName' => 'Test', + 'LastName' => 'user' + ], + 'isHavingOwnHouse' => 1, + 'address' => + [ + 'street' => '1st Street', + 'city' => 'London' + ], + ] + ], + ] + ]; + } +} diff --git a/app/code/Magento/Customer/etc/webapi_rest/di.xml b/app/code/Magento/Customer/etc/webapi_rest/di.xml index 18627b68320ed..c5d7a28a3651d 100644 --- a/app/code/Magento/Customer/etc/webapi_rest/di.xml +++ b/app/code/Magento/Customer/etc/webapi_rest/di.xml @@ -31,6 +31,9 @@ + + + From 5d35300f0ac6b15e3308f394f0b8751cc5fb4241 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Thu, 21 Jul 2022 15:55:13 +0530 Subject: [PATCH 02/14] Magento Admin stores functionality improvements --- .../Block/System/Store/Grid/Render/Group.php | 2 +- app/code/Magento/Store/Model/Group.php | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 3d7154eb20f92..0fd64eb9e1ff6 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -28,6 +28,6 @@ public function render(\Magento\Framework\DataObject $row) '">' . $this->escapeHtml($row->getData($this->getColumn()->getIndex())) . '
' - . '(' . __('Code') . ': ' . $row->getGroupCode() . ')'; + . '(' . __('Code') . ': ' . $this->escapeHtml($row->getGroupCode()) . ')'; } } diff --git a/app/code/Magento/Store/Model/Group.php b/app/code/Magento/Store/Model/Group.php index 7f1e71c422251..4d6d7e9770a17 100644 --- a/app/code/Magento/Store/Model/Group.php +++ b/app/code/Magento/Store/Model/Group.php @@ -9,6 +9,8 @@ */ namespace Magento\Store\Model; +use Magento\Framework\App\ObjectManager; + /** * Class Group * @@ -105,6 +107,11 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements */ private $pillPut; + /** + * @var \Magento\Store\Model\Validation\StoreValidator + */ + private $modelValidator; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -118,6 +125,7 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements * @param array $data * @param \Magento\Framework\Event\ManagerInterface|null $eventManager * @param \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface|null $pillPut + * @param \Magento\Store\Model\Validation\StoreValidator|null $modelValidator * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -132,7 +140,8 @@ public function __construct( \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], \Magento\Framework\Event\ManagerInterface $eventManager = null, - \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null + \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null, + \Magento\Store\Model\Validation\StoreValidator $modelValidator = null ) { $this->_configDataResource = $configDataResource; $this->_storeListFactory = $storeListFactory; @@ -141,6 +150,8 @@ public function __construct( ->get(\Magento\Framework\Event\ManagerInterface::class); $this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class); + $this->modelValidator = $modelValidator ?: ObjectManager::getInstance() + ->get(\Magento\Store\Model\Validation\StoreValidator::class); parent::__construct( $context, $registry, @@ -162,6 +173,17 @@ protected function _construct() $this->_init(\Magento\Store\Model\ResourceModel\Group::class); } + /** + * Validation rules for store + * + * @return \Zend_Validate_Interface|null + * @throws \Zend_Validate_Exception + */ + protected function _getValidationRulesBeforeSave() + { + return $this->modelValidator; + } + /** * Load store collection and set internal data * From a2674dde75e6199580ef62f4fa7bcf2c50d7107f Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Fri, 22 Jul 2022 18:09:47 +0530 Subject: [PATCH 03/14] Magento Admin stores functionality improvements --- .../Block/System/Store/Grid/Render/Group.php | 7 +- app/code/Magento/Store/Model/Group.php | 142 ++++++++++-------- 2 files changed, 85 insertions(+), 64 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 0fd64eb9e1ff6..92738633af746 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -5,17 +5,20 @@ */ namespace Magento\Backend\Block\System\Store\Grid\Render; +use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer; +use Magento\Framework\DataObject; + /** * Store render group * * @author Magento Core Team */ -class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer +class Group extends AbstractRenderer { /** * {@inheritdoc} */ - public function render(\Magento\Framework\DataObject $row) + public function render(DataObject $row): ?string { if (!$row->getData($this->getColumn()->getIndex())) { return null; diff --git a/app/code/Magento/Store/Model/Group.php b/app/code/Magento/Store/Model/Group.php index 4d6d7e9770a17..146b5df037f87 100644 --- a/app/code/Magento/Store/Model/Group.php +++ b/app/code/Magento/Store/Model/Group.php @@ -9,7 +9,25 @@ */ namespace Magento\Store\Model; +use Magento\Config\Model\ResourceModel\Config\Data as ConfigData; +use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\Api\ExtensionAttributesFactory; use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\ScopeInterface as AppScopeInterface; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface; +use Magento\Framework\Model\AbstractExtensibleModel; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Store\Api\Data\GroupExtensionInterface; +use Magento\Store\Api\Data\GroupInterface; +use Magento\Store\Model\ResourceModel\Store\Collection; +use Magento\Store\Model\ResourceModel\Store\CollectionFactory; +use Magento\Store\Model\ResourceModel\Group as ResourceModelGroup; +use Magento\Store\Model\Validation\StoreValidator; /** * Class Group @@ -18,10 +36,10 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements - \Magento\Framework\DataObject\IdentityInterface, - \Magento\Store\Api\Data\GroupInterface, - \Magento\Framework\App\ScopeInterface +class Group extends AbstractExtensibleModel implements + IdentityInterface, + GroupInterface, + AppScopeInterface { const ENTITY = 'store_group'; @@ -45,7 +63,7 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements /** * Group Store collection array * - * @var \Magento\Store\Model\ResourceModel\Store\Collection[] + * @var Collection[] */ protected $_stores; @@ -73,7 +91,7 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements /** * Group default store * - * @var \Magento\Store\Model\Store + * @var Store */ protected $_defaultStore; @@ -83,75 +101,75 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements private $_isReadOnly = false; /** - * @var \Magento\Config\Model\ResourceModel\Config\Data + * @var ConfigData */ protected $_configDataResource; /** - * @var \Magento\Store\Model\Store + * @var Store */ protected $_storeListFactory; /** - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** - * @var \Magento\Framework\Event\ManagerInterface + * @var ManagerInterface */ private $eventManager; /** - * @var \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface + * @var PoisonPillPutInterface */ private $pillPut; /** - * @var \Magento\Store\Model\Validation\StoreValidator + * @var StoreValidator */ private $modelValidator; /** - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Config\Model\ResourceModel\Config\Data $configDataResource - * @param ResourceModel\Store\CollectionFactory $storeListFactory + * @param Context $context + * @param Registry $registry + * @param ExtensionAttributesFactory $extensionFactory + * @param AttributeValueFactory $customAttributeFactory + * @param ConfigData $configDataResource + * @param CollectionFactory $storeListFactory * @param StoreManagerInterface $storeManager - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection + * @param AbstractResource|null $resource + * @param AbstractDb|null $resourceCollection * @param array $data - * @param \Magento\Framework\Event\ManagerInterface|null $eventManager - * @param \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface|null $pillPut - * @param \Magento\Store\Model\Validation\StoreValidator|null $modelValidator + * @param ManagerInterface|null $eventManager + * @param PoisonPillPutInterface|null $pillPut + * @param StoreValidator|null $modelValidator * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Config\Model\ResourceModel\Config\Data $configDataResource, - \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeListFactory, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + Context $context, + Registry $registry, + ExtensionAttributesFactory $extensionFactory, + AttributeValueFactory $customAttributeFactory, + ConfigData $configDataResource, + CollectionFactory $storeListFactory, + StoreManagerInterface $storeManager, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [], - \Magento\Framework\Event\ManagerInterface $eventManager = null, - \Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface $pillPut = null, - \Magento\Store\Model\Validation\StoreValidator $modelValidator = null + ManagerInterface $eventManager = null, + PoisonPillPutInterface $pillPut = null, + StoreValidator $modelValidator = null ) { $this->_configDataResource = $configDataResource; $this->_storeListFactory = $storeListFactory; $this->_storeManager = $storeManager; - $this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Event\ManagerInterface::class); - $this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface::class); + $this->eventManager = $eventManager ?: ObjectManager::getInstance() + ->get(ManagerInterface::class); + $this->pillPut = $pillPut ?: ObjectManager::getInstance() + ->get(PoisonPillPutInterface::class); $this->modelValidator = $modelValidator ?: ObjectManager::getInstance() - ->get(\Magento\Store\Model\Validation\StoreValidator::class); + ->get(StoreValidator::class); parent::__construct( $context, $registry, @@ -170,7 +188,7 @@ public function __construct( */ protected function _construct() { - $this->_init(\Magento\Store\Model\ResourceModel\Group::class); + $this->_init(ResourceModelGroup::class); } /** @@ -189,7 +207,7 @@ protected function _getValidationRulesBeforeSave() * * @return void */ - protected function _loadStores() + protected function _loadStores(): void { $this->_stores = []; $this->_storesCount = 0; @@ -207,10 +225,10 @@ protected function _loadStores() /** * Set website stores * - * @param \Magento\Store\Model\Store[] $stores + * @param Store[] $stores * @return void */ - public function setStores($stores) + public function setStores($stores): void { $this->_stores = []; $this->_storesCount = 0; @@ -228,9 +246,9 @@ public function setStores($stores) /** * Retrieve new (not loaded) Store collection object with group filter * - * @return \Magento\Store\Model\ResourceModel\Store\Collection + * @return Collection */ - public function getStoreCollection() + public function getStoreCollection(): Collection { return $this->_storeListFactory->create()->addGroupFilter($this->getId()); } @@ -238,9 +256,9 @@ public function getStoreCollection() /** * Retrieve website store objects * - * @return \Magento\Store\Model\ResourceModel\Store\Collection[] + * @return Collection[] */ - public function getStores() + public function getStores(): array { if ($this->_stores === null) { $this->_loadStores(); @@ -253,7 +271,7 @@ public function getStores() * * @return int[] */ - public function getStoreIds() + public function getStoreIds(): array { if ($this->_stores === null) { $this->_loadStores(); @@ -266,7 +284,7 @@ public function getStoreIds() * * @return array */ - public function getStoreCodes() + public function getStoreCodes(): array { if ($this->_stores === null) { $this->_loadStores(); @@ -279,7 +297,7 @@ public function getStoreCodes() * * @return int */ - public function getStoresCount() + public function getStoresCount(): int { if ($this->_stores === null) { $this->_loadStores(); @@ -290,7 +308,7 @@ public function getStoresCount() /** * Retrieve default store model * - * @return \Magento\Store\Model\Store + * @return Store|bool */ public function getDefaultStore() { @@ -309,7 +327,7 @@ public function getDefaultStore() * If group has no stores - null is returned * * @param string $locale - * @return \Magento\Store\Model\Store|null + * @return Store|null */ public function getDefaultStoreByLocale($locale) { @@ -329,13 +347,13 @@ public function getDefaultStoreByLocale($locale) * Retrieve list of stores with given locale * * @param string $locale - * @return \Magento\Store\Model\Store[] + * @return Store[] */ - public function getStoresByLocale($locale) + public function getStoresByLocale($locale): array { $stores = []; foreach ($this->getStores() as $store) { - /* @var $store \Magento\Store\Model\Store */ + /* @var Store $store */ if ($store->getLocaleCode() == $locale) { $stores[] = $store; } @@ -349,7 +367,7 @@ public function getStoresByLocale($locale) * @param Website $website * @return void */ - public function setWebsite(Website $website) + public function setWebsite(Website $website): void { $this->setWebsiteId($website->getId()); } @@ -372,7 +390,7 @@ public function getWebsite() * * @return bool */ - public function isCanDelete() + public function isCanDelete(): bool { if (!$this->getId()) { return false; @@ -441,7 +459,7 @@ public function setWebsiteId($websiteId) public function beforeDelete() { $this->_configDataResource->clearScopeData( - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, + ScopeInterface::SCOPE_STORES, $this->getStoreIds() ); return parent::beforeDelete(); @@ -495,7 +513,7 @@ public function afterSave() * @param bool $value * @return bool */ - public function isReadOnly($value = null) + public function isReadOnly($value = null): bool { if (null !== $value) { $this->_isReadOnly = (bool)$value; @@ -508,7 +526,7 @@ public function isReadOnly($value = null) * * @return array */ - public function getIdentities() + public function getIdentities(): array { return [self::CACHE_TAG]; } @@ -559,7 +577,7 @@ public function getExtensionAttributes() * @inheritdoc */ public function setExtensionAttributes( - \Magento\Store\Api\Data\GroupExtensionInterface $extensionAttributes + GroupExtensionInterface $extensionAttributes ) { return $this->_setExtensionAttributes($extensionAttributes); } From 6696f954b160afaff73f0361f4d16e62608bf4e4 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Mon, 25 Jul 2022 14:42:39 +0530 Subject: [PATCH 04/14] Magento Admin stores functionality improvements --- .../Block/System/Store/Grid/Render/Group.php | 6 +- app/code/Magento/Store/Model/Group.php | 124 ++++++++---------- 2 files changed, 56 insertions(+), 74 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 92738633af746..49318dc875c16 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -5,20 +5,18 @@ */ namespace Magento\Backend\Block\System\Store\Grid\Render; -use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer; -use Magento\Framework\DataObject; /** * Store render group * * @author Magento Core Team */ -class Group extends AbstractRenderer +class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { /** * {@inheritdoc} */ - public function render(DataObject $row): ?string + public function render(\Magento\Framework\DataObject $row) { if (!$row->getData($this->getColumn()->getIndex())) { return null; diff --git a/app/code/Magento/Store/Model/Group.php b/app/code/Magento/Store/Model/Group.php index 146b5df037f87..ddd9097f5dbd7 100644 --- a/app/code/Magento/Store/Model/Group.php +++ b/app/code/Magento/Store/Model/Group.php @@ -9,24 +9,8 @@ */ namespace Magento\Store\Model; -use Magento\Config\Model\ResourceModel\Config\Data as ConfigData; -use Magento\Framework\Api\AttributeValueFactory; -use Magento\Framework\Api\ExtensionAttributesFactory; use Magento\Framework\App\ObjectManager; -use Magento\Framework\App\ScopeInterface as AppScopeInterface; -use Magento\Framework\Data\Collection\AbstractDb; -use Magento\Framework\DataObject\IdentityInterface; -use Magento\Framework\Event\ManagerInterface; use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface; -use Magento\Framework\Model\AbstractExtensibleModel; -use Magento\Framework\Model\Context; -use Magento\Framework\Model\ResourceModel\AbstractResource; -use Magento\Framework\Registry; -use Magento\Store\Api\Data\GroupExtensionInterface; -use Magento\Store\Api\Data\GroupInterface; -use Magento\Store\Model\ResourceModel\Store\Collection; -use Magento\Store\Model\ResourceModel\Store\CollectionFactory; -use Magento\Store\Model\ResourceModel\Group as ResourceModelGroup; use Magento\Store\Model\Validation\StoreValidator; /** @@ -36,10 +20,10 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ -class Group extends AbstractExtensibleModel implements - IdentityInterface, - GroupInterface, - AppScopeInterface +class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements + \Magento\Framework\DataObject\IdentityInterface, + \Magento\Store\Api\Data\GroupInterface, + \Magento\Framework\App\ScopeInterface { const ENTITY = 'store_group'; @@ -63,7 +47,7 @@ class Group extends AbstractExtensibleModel implements /** * Group Store collection array * - * @var Collection[] + * @var \Magento\Store\Model\ResourceModel\Store\Collection[] */ protected $_stores; @@ -91,7 +75,7 @@ class Group extends AbstractExtensibleModel implements /** * Group default store * - * @var Store + * @var \Magento\Store\Model\Store */ protected $_defaultStore; @@ -101,22 +85,22 @@ class Group extends AbstractExtensibleModel implements private $_isReadOnly = false; /** - * @var ConfigData + * @var \Magento\Config\Model\ResourceModel\Config\Data */ protected $_configDataResource; /** - * @var Store + * @var \Magento\Store\Model\Store */ protected $_storeListFactory; /** - * @var StoreManagerInterface + * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; /** - * @var ManagerInterface + * @var \Magento\Framework\Event\ManagerInterface */ private $eventManager; @@ -131,42 +115,42 @@ class Group extends AbstractExtensibleModel implements private $modelValidator; /** - * @param Context $context - * @param Registry $registry - * @param ExtensionAttributesFactory $extensionFactory - * @param AttributeValueFactory $customAttributeFactory - * @param ConfigData $configDataResource - * @param CollectionFactory $storeListFactory + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory + * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory + * @param \Magento\Config\Model\ResourceModel\Config\Data $configDataResource + * @param ResourceModel\Store\CollectionFactory $storeListFactory * @param StoreManagerInterface $storeManager - * @param AbstractResource|null $resource - * @param AbstractDb|null $resourceCollection + * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource + * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data - * @param ManagerInterface|null $eventManager + * @param \Magento\Framework\Event\ManagerInterface|null $eventManager * @param PoisonPillPutInterface|null $pillPut * @param StoreValidator|null $modelValidator * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - Context $context, - Registry $registry, - ExtensionAttributesFactory $extensionFactory, - AttributeValueFactory $customAttributeFactory, - ConfigData $configDataResource, - CollectionFactory $storeListFactory, - StoreManagerInterface $storeManager, - AbstractResource $resource = null, - AbstractDb $resourceCollection = null, + \Magento\Framework\Model\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, + \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, + \Magento\Config\Model\ResourceModel\Config\Data $configDataResource, + \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeListFactory, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, + \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - ManagerInterface $eventManager = null, + \Magento\Framework\Event\ManagerInterface $eventManager = null, PoisonPillPutInterface $pillPut = null, StoreValidator $modelValidator = null ) { $this->_configDataResource = $configDataResource; $this->_storeListFactory = $storeListFactory; $this->_storeManager = $storeManager; - $this->eventManager = $eventManager ?: ObjectManager::getInstance() - ->get(ManagerInterface::class); - $this->pillPut = $pillPut ?: ObjectManager::getInstance() + $this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Event\ManagerInterface::class); + $this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(PoisonPillPutInterface::class); $this->modelValidator = $modelValidator ?: ObjectManager::getInstance() ->get(StoreValidator::class); @@ -188,7 +172,7 @@ public function __construct( */ protected function _construct() { - $this->_init(ResourceModelGroup::class); + $this->_init(\Magento\Store\Model\ResourceModel\Group::class); } /** @@ -197,7 +181,7 @@ protected function _construct() * @return \Zend_Validate_Interface|null * @throws \Zend_Validate_Exception */ - protected function _getValidationRulesBeforeSave() + protected function _getValidationRulesBeforeSave(): ?Object { return $this->modelValidator; } @@ -207,7 +191,7 @@ protected function _getValidationRulesBeforeSave() * * @return void */ - protected function _loadStores(): void + protected function _loadStores() { $this->_stores = []; $this->_storesCount = 0; @@ -225,10 +209,10 @@ protected function _loadStores(): void /** * Set website stores * - * @param Store[] $stores + * @param \Magento\Store\Model\Store[] $stores * @return void */ - public function setStores($stores): void + public function setStores($stores) { $this->_stores = []; $this->_storesCount = 0; @@ -246,9 +230,9 @@ public function setStores($stores): void /** * Retrieve new (not loaded) Store collection object with group filter * - * @return Collection + * @return \Magento\Store\Model\ResourceModel\Store\Collection */ - public function getStoreCollection(): Collection + public function getStoreCollection() { return $this->_storeListFactory->create()->addGroupFilter($this->getId()); } @@ -256,9 +240,9 @@ public function getStoreCollection(): Collection /** * Retrieve website store objects * - * @return Collection[] + * @return \Magento\Store\Model\ResourceModel\Store\Collection[] */ - public function getStores(): array + public function getStores() { if ($this->_stores === null) { $this->_loadStores(); @@ -271,7 +255,7 @@ public function getStores(): array * * @return int[] */ - public function getStoreIds(): array + public function getStoreIds() { if ($this->_stores === null) { $this->_loadStores(); @@ -284,7 +268,7 @@ public function getStoreIds(): array * * @return array */ - public function getStoreCodes(): array + public function getStoreCodes() { if ($this->_stores === null) { $this->_loadStores(); @@ -297,7 +281,7 @@ public function getStoreCodes(): array * * @return int */ - public function getStoresCount(): int + public function getStoresCount() { if ($this->_stores === null) { $this->_loadStores(); @@ -308,7 +292,7 @@ public function getStoresCount(): int /** * Retrieve default store model * - * @return Store|bool + * @return \Magento\Store\Model\Store */ public function getDefaultStore() { @@ -327,7 +311,7 @@ public function getDefaultStore() * If group has no stores - null is returned * * @param string $locale - * @return Store|null + * @return \Magento\Store\Model\Store|null */ public function getDefaultStoreByLocale($locale) { @@ -347,13 +331,13 @@ public function getDefaultStoreByLocale($locale) * Retrieve list of stores with given locale * * @param string $locale - * @return Store[] + * @return \Magento\Store\Model\Store[] */ - public function getStoresByLocale($locale): array + public function getStoresByLocale($locale) { $stores = []; foreach ($this->getStores() as $store) { - /* @var Store $store */ + /* @var $store \Magento\Store\Model\Store */ if ($store->getLocaleCode() == $locale) { $stores[] = $store; } @@ -367,7 +351,7 @@ public function getStoresByLocale($locale): array * @param Website $website * @return void */ - public function setWebsite(Website $website): void + public function setWebsite(Website $website) { $this->setWebsiteId($website->getId()); } @@ -390,7 +374,7 @@ public function getWebsite() * * @return bool */ - public function isCanDelete(): bool + public function isCanDelete() { if (!$this->getId()) { return false; @@ -459,7 +443,7 @@ public function setWebsiteId($websiteId) public function beforeDelete() { $this->_configDataResource->clearScopeData( - ScopeInterface::SCOPE_STORES, + \Magento\Store\Model\ScopeInterface::SCOPE_STORES, $this->getStoreIds() ); return parent::beforeDelete(); @@ -513,7 +497,7 @@ public function afterSave() * @param bool $value * @return bool */ - public function isReadOnly($value = null): bool + public function isReadOnly($value = null) { if (null !== $value) { $this->_isReadOnly = (bool)$value; @@ -526,7 +510,7 @@ public function isReadOnly($value = null): bool * * @return array */ - public function getIdentities(): array + public function getIdentities() { return [self::CACHE_TAG]; } From 16ec9a1a0b1b0dc4039107b9ca8df08de00d812f Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Mon, 25 Jul 2022 14:46:33 +0530 Subject: [PATCH 05/14] Magento Admin stores functionality improvements --- .../Magento/Backend/Block/System/Store/Grid/Render/Group.php | 1 - app/code/Magento/Store/Model/Group.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 49318dc875c16..0fd64eb9e1ff6 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -5,7 +5,6 @@ */ namespace Magento\Backend\Block\System\Store\Grid\Render; - /** * Store render group * diff --git a/app/code/Magento/Store/Model/Group.php b/app/code/Magento/Store/Model/Group.php index ddd9097f5dbd7..5b1c3bc93f4a1 100644 --- a/app/code/Magento/Store/Model/Group.php +++ b/app/code/Magento/Store/Model/Group.php @@ -561,7 +561,7 @@ public function getExtensionAttributes() * @inheritdoc */ public function setExtensionAttributes( - GroupExtensionInterface $extensionAttributes + \Magento\Store\Api\Data\GroupExtensionInterface $extensionAttributes ) { return $this->_setExtensionAttributes($extensionAttributes); } From fb4e66e306fed18dc9de03a5cf359d801cb67475 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Mon, 25 Jul 2022 17:38:40 +0530 Subject: [PATCH 06/14] Magento Admin stores functionality improvements --- app/code/Magento/Store/Model/Group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Store/Model/Group.php b/app/code/Magento/Store/Model/Group.php index 5b1c3bc93f4a1..e48d4f508f704 100644 --- a/app/code/Magento/Store/Model/Group.php +++ b/app/code/Magento/Store/Model/Group.php @@ -181,7 +181,7 @@ protected function _construct() * @return \Zend_Validate_Interface|null * @throws \Zend_Validate_Exception */ - protected function _getValidationRulesBeforeSave(): ?Object + protected function _getValidationRulesBeforeSave(): ?\Zend_Validate_Interface { return $this->modelValidator; } From 2215dfcdce84b04b8b20dddece9e3ef1b6a93951 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Tue, 26 Jul 2022 13:42:26 +0530 Subject: [PATCH 07/14] Magento Admin stores functionality improvements --- .../Catalog/Model/Indexer/Product/Flat/ProcessorTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php index 5b9266dc11371..ac50daf477801 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php @@ -145,7 +145,13 @@ public function testAddNewStoreGroup(): void \Magento\Store\Model\Group::class ); $storeGroup->setData( - ['website_id' => 1, 'name' => 'New Store Group', 'root_category_id' => 2, 'group_id' => null] + [ + 'website_id' => 1, + 'name' => 'New Store Group', + 'root_category_id' => 2, + 'group_id' => null, + 'code' => 'newstoregroup' + ] ); $storeGroup->save(); $this->assertTrue($this->processor->getIndexer()->isInvalid()); From 2882495e422960a6c2cb9410923e73eb07d30394 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Tue, 26 Jul 2022 16:15:23 +0530 Subject: [PATCH 08/14] Magento Admin stores functionality improvements --- .../Catalog/Console/Command/ProductAttributesCleanUpTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ProductAttributesCleanUpTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ProductAttributesCleanUpTest.php index 9d3f11eb1247a..390ad01173882 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ProductAttributesCleanUpTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ProductAttributesCleanUpTest.php @@ -104,6 +104,7 @@ private function prepareAdditionalStore() $storeGroup = $this->objectManager->create(\Magento\Store\Model\Group::class); $storeGroup->setWebsiteId($website->getId()); $storeGroup->setName('Fixture Store Group'); + $storeGroup->setCode('fixturestoregroup'); $storeGroup->setRootCategoryId(2); $storeGroup->setDefaultStoreId($store->getId()); $storeGroup->save(); From 500d4f9a34767ed7f37036c27a4c7459c4839381 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Tue, 2 Aug 2022 16:49:19 +0530 Subject: [PATCH 09/14] Magento Admin stores functionality improvements --- .../Backend/Block/System/Store/Grid/Render/Group.php | 5 +++-- app/code/Magento/Store/Model/Group.php | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 0fd64eb9e1ff6..fc7e77b253fef 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -13,9 +13,10 @@ class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { /** - * {@inheritdoc} + * @inheritdoc + * @return string|null */ - public function render(\Magento\Framework\DataObject $row) + public function render(\Magento\Framework\DataObject $row): ?string { if (!$row->getData($this->getColumn()->getIndex())) { return null; diff --git a/app/code/Magento/Store/Model/Group.php b/app/code/Magento/Store/Model/Group.php index e48d4f508f704..7593a788e092e 100644 --- a/app/code/Magento/Store/Model/Group.php +++ b/app/code/Magento/Store/Model/Group.php @@ -14,7 +14,7 @@ use Magento\Store\Model\Validation\StoreValidator; /** - * Class Group + * Store Group model class used to retrieve and format group information * * @api * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -25,9 +25,9 @@ class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements \Magento\Store\Api\Data\GroupInterface, \Magento\Framework\App\ScopeInterface { - const ENTITY = 'store_group'; + public const ENTITY = 'store_group'; - const CACHE_TAG = 'store_group'; + public const CACHE_TAG = 'store_group'; /** * @var bool From dc8e09a214406bc9b750461bedfed97d5199ff0b Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Thu, 4 Aug 2022 18:17:26 +0530 Subject: [PATCH 10/14] Magento Admin stores functionality improvements --- .../Magento/Backend/Block/System/Store/Grid/Render/Group.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index fc7e77b253fef..4eae09cd586b0 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -13,8 +13,9 @@ class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { /** + * Render action + * * @inheritdoc - * @return string|null */ public function render(\Magento\Framework\DataObject $row): ?string { From 18c4a75bfc67ff118122852fc8738f3762616377 Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Thu, 4 Aug 2022 18:33:49 +0530 Subject: [PATCH 11/14] Magento Admin stores functionality improvements --- .../Magento/Backend/Block/System/Store/Grid/Render/Group.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 4eae09cd586b0..1d09eecee98f1 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -13,9 +13,7 @@ class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { /** - * Render action - * - * @inheritdoc + * {@inheritdoc} Render action */ public function render(\Magento\Framework\DataObject $row): ?string { From 3d54c6672c6dfb10fe24d581738e23e660ed168c Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Fri, 5 Aug 2022 11:28:05 +0530 Subject: [PATCH 12/14] Magento Admin stores functionality improvements --- .../Catalog/Model/Indexer/Product/Flat/ProcessorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php index ac50daf477801..0e454a854d8ff 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/ProcessorTest.php @@ -1,9 +1,9 @@ Date: Fri, 5 Aug 2022 17:06:48 +0530 Subject: [PATCH 13/14] Magento Admin stores functionality improvements --- .../Magento/Backend/Block/System/Store/Grid/Render/Group.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 1d09eecee98f1..169118f143864 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Block\System\Store\Grid\Render; +use Magento\Framework\DataObject; + /** * Store render group * @@ -14,8 +16,9 @@ class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractR { /** * {@inheritdoc} Render action + * @param DataObject $row */ - public function render(\Magento\Framework\DataObject $row): ?string + public function render(DataObject $row): ?string { if (!$row->getData($this->getColumn()->getIndex())) { return null; From f39118a3c67798843eb94efcf9f14e43d7ffaa7d Mon Sep 17 00:00:00 2001 From: Sreeni A Date: Fri, 5 Aug 2022 17:40:40 +0530 Subject: [PATCH 14/14] Magento Admin stores functionality improvements --- .../Magento/Backend/Block/System/Store/Grid/Render/Group.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php index 169118f143864..db8f952207aa3 100644 --- a/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php +++ b/app/code/Magento/Backend/Block/System/Store/Grid/Render/Group.php @@ -15,8 +15,7 @@ class Group extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { /** - * {@inheritdoc} Render action - * @param DataObject $row + * @inheritDoc */ public function render(DataObject $row): ?string {