Skip to content

Commit bc8f909

Browse files
matthew-muscatmage2pratik
authored andcommitted
Resolve incorrect scope code selection when the requested scopeCode is null
- resolves an issue whereby the incorrect scope could be returned when attempting to resolve a scope with a requested scopeCode of null - simplify the scope resolver logic to a avoid multiple if conditional checks - move scope interface class to an alias of the class - update docblock on the expected values available for scopeCode Signed-off-by: Matthew Muscat <matthew@mamis.com.au>
1 parent c427332 commit bc8f909

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\App\Config;
77

8+
use Magento\Framework\App\ScopeInterface;
89
use Magento\Framework\App\ScopeResolverPool;
910

1011
/**
@@ -34,28 +35,33 @@ public function __construct(ScopeResolverPool $scopeResolverPool)
3435
* Resolve scope code
3536
*
3637
* @param string $scopeType
37-
* @param string $scopeCode
38+
* @param string|null $scopeCode
3839
* @return string
3940
*/
4041
public function resolve($scopeType, $scopeCode)
4142
{
4243
if (isset($this->resolvedScopeCodes[$scopeType][$scopeCode])) {
4344
return $this->resolvedScopeCodes[$scopeType][$scopeCode];
4445
}
45-
if (($scopeCode === null || is_numeric($scopeCode))
46-
&& $scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT
47-
) {
46+
47+
if ($scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
4848
$scopeResolver = $this->scopeResolverPool->get($scopeType);
4949
$resolverScopeCode = $scopeResolver->getScope($scopeCode);
50-
} else {
50+
}
51+
else {
5152
$resolverScopeCode = $scopeCode;
5253
}
5354

54-
if ($resolverScopeCode instanceof \Magento\Framework\App\ScopeInterface) {
55+
if ($resolverScopeCode instanceof ScopeInterface) {
5556
$resolverScopeCode = $resolverScopeCode->getCode();
5657
}
5758

59+
if ($scopeCode == null) {
60+
$scopeCode = $resolverScopeCode;
61+
}
62+
5863
$this->resolvedScopeCodes[$scopeType][$scopeCode] = $resolverScopeCode;
64+
5965
return $resolverScopeCode;
6066
}
6167

0 commit comments

Comments
 (0)