12
12
use Magento \Framework \App \ScopeInterface ;
13
13
use Magento \Framework \App \ScopeResolverPool ;
14
14
use Magento \Store \Model \ScopeInterface as StoreScopeInterface ;
15
+ use Magento \Store \Model \ScopeTypeNormalizer ;
15
16
16
17
/**
17
18
* Backend config model
@@ -108,6 +109,11 @@ class Config extends \Magento\Framework\DataObject
108
109
*/
109
110
private $ scopeResolverPool ;
110
111
112
+ /**
113
+ * @var ScopeTypeNormalizer
114
+ */
115
+ private $ scopeTypeNormalizer ;
116
+
111
117
/**
112
118
* @param \Magento\Framework\App\Config\ReinitableConfigInterface $config
113
119
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -119,6 +125,7 @@ class Config extends \Magento\Framework\DataObject
119
125
* @param Config\Reader\Source\Deployed\SettingChecker|null $settingChecker
120
126
* @param array $data
121
127
* @param ScopeResolverPool|null $scopeResolverPool
128
+ * @param ScopeTypeNormalizer|null $scopeTypeNormalizer
122
129
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
123
130
*/
124
131
public function __construct (
@@ -131,7 +138,8 @@ public function __construct(
131
138
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
132
139
SettingChecker $ settingChecker = null ,
133
140
array $ data = [],
134
- ScopeResolverPool $ scopeResolverPool = null
141
+ ScopeResolverPool $ scopeResolverPool = null ,
142
+ ScopeTypeNormalizer $ scopeTypeNormalizer = null
135
143
) {
136
144
parent ::__construct ($ data );
137
145
$ this ->_eventManager = $ eventManager ;
@@ -141,8 +149,12 @@ public function __construct(
141
149
$ this ->_configLoader = $ configLoader ;
142
150
$ this ->_configValueFactory = $ configValueFactory ;
143
151
$ this ->_storeManager = $ storeManager ;
144
- $ this ->settingChecker = $ settingChecker ?? ObjectManager::getInstance ()->get (SettingChecker::class);
145
- $ this ->scopeResolverPool = $ scopeResolverPool ?? ObjectManager::getInstance ()->get (ScopeResolverPool::class);
152
+ $ this ->settingChecker = $ settingChecker
153
+ ?? ObjectManager::getInstance ()->get (SettingChecker::class);
154
+ $ this ->scopeResolverPool = $ scopeResolverPool
155
+ ?? ObjectManager::getInstance ()->get (ScopeResolverPool::class);
156
+ $ this ->scopeTypeNormalizer = $ scopeTypeNormalizer
157
+ ?? ObjectManager::getInstance ()->get (ScopeTypeNormalizer::class);
146
158
}
147
159
148
160
/**
@@ -539,53 +551,34 @@ private function initScope()
539
551
if ($ this ->getSection () === null ) {
540
552
$ this ->setSection ('' );
541
553
}
542
- if ($ this ->getWebsite () === null ) {
543
- $ this ->setWebsite ('' );
544
- }
545
- if ($ this ->getStore () === null ) {
546
- $ this ->setStore ('' );
547
- }
548
554
549
- if ($ this ->getScope ()) {
550
- $ scope = $ this ->scopeResolverPool ->get ($ this ->getScope ())
551
- ->getScope ($ this ->getScopeCode ());
552
- if (StoreScopeInterface::SCOPE_WEBSITE === $ scope ->getScopeType ()) {
553
- $ this ->setWebsite ($ scope ->getId ());
554
- } elseif (StoreScopeInterface::SCOPE_STORE === $ scope ->getScopeType ()) {
555
- $ this ->setStore ($ scope ->getId ());
555
+ if (!$ this ->getScope ()) {
556
+ switch (true ) {
557
+ case $ this ->getStore ():
558
+ $ this ->setScope (StoreScopeInterface::SCOPE_STORES );
559
+ $ this ->setScopeCode ($ this ->getStore ());
560
+ break ;
561
+ case $ this ->getWebsite ():
562
+ $ this ->setScope (StoreScopeInterface::SCOPE_WEBSITES );
563
+ $ this ->setScopeCode ($ this ->getWebsite ());
564
+ break ;
565
+ default :
566
+ $ this ->setScope (ScopeInterface::SCOPE_DEFAULT );
567
+ $ this ->setScopeCode ('' );
568
+ break ;
556
569
}
557
- $ this ->setScopeId ($ scope ->getId ());
558
- } else {
559
- $ scope = $ this ->resolveScope ();
560
- $ this ->setScope ($ scope ->getScopeType ());
561
- $ this ->setScopeId ($ scope ->getId ());
562
- $ this ->setScopeCode ($ scope ->getCode ());
563
570
}
564
- }
565
-
566
- /**
567
- * Resolve scope
568
- *
569
- * @return ScopeInterface
570
- */
571
- private function resolveScope (): ScopeInterface
572
- {
573
- switch (true ) {
574
- case $ this ->getStore ():
575
- $ scope = $ this ->scopeResolverPool ->get (StoreScopeInterface::SCOPE_STORE )
576
- ->getScope ($ this ->getStore ());
577
- break ;
578
- case $ this ->getWebsite ():
579
- $ scope = $ this ->scopeResolverPool ->get (StoreScopeInterface::SCOPE_WEBSITE )
580
- ->getScope ($ this ->getWebsite ());
581
- break ;
582
- default :
583
- $ scope = $ this ->scopeResolverPool ->get (ScopeInterface::SCOPE_DEFAULT )
584
- ->getScope (0 );
585
- break ;
571
+ $ scope = $ this ->scopeResolverPool ->get ($ this ->getScope ())
572
+ ->getScope ($ this ->getScopeCode ());
573
+ $ this ->setScope ($ this ->scopeTypeNormalizer ->normalize ($ scope ->getScopeType ()));
574
+ $ this ->setScopeCode ($ scope ->getCode ());
575
+ $ this ->setScopeId ($ scope ->getId ());
576
+ if ($ this ->getWebsite () === null ) {
577
+ $ this ->setWebsite (StoreScopeInterface::SCOPE_WEBSITES === $ this ->getScope () ? $ scope ->getId () : '' );
578
+ }
579
+ if ($ this ->getStore () === null ) {
580
+ $ this ->setStore (StoreScopeInterface::SCOPE_STORES === $ this ->getScope () ? $ scope ->getId () : '' );
586
581
}
587
-
588
- return $ scope ;
589
582
}
590
583
591
584
/**
0 commit comments