Skip to content

Commit

Permalink
Resolve incorrect scope code selection when the requested scopeCode i…
Browse files Browse the repository at this point in the history
…s 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>
  • Loading branch information
matthew-muscat authored and mage2pratik committed Mar 7, 2019
1 parent c427332 commit bc8f909
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/internal/Magento/Framework/App/Config/ScopeCodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Framework\App\Config;

use Magento\Framework\App\ScopeInterface;
use Magento\Framework\App\ScopeResolverPool;

/**
Expand Down Expand Up @@ -34,28 +35,33 @@ public function __construct(ScopeResolverPool $scopeResolverPool)
* Resolve scope code
*
* @param string $scopeType
* @param string $scopeCode
* @param string|null $scopeCode
* @return string
*/
public function resolve($scopeType, $scopeCode)
{
if (isset($this->resolvedScopeCodes[$scopeType][$scopeCode])) {
return $this->resolvedScopeCodes[$scopeType][$scopeCode];
}
if (($scopeCode === null || is_numeric($scopeCode))
&& $scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT
) {

if ($scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
$scopeResolver = $this->scopeResolverPool->get($scopeType);
$resolverScopeCode = $scopeResolver->getScope($scopeCode);
} else {
}
else {
$resolverScopeCode = $scopeCode;
}

if ($resolverScopeCode instanceof \Magento\Framework\App\ScopeInterface) {
if ($resolverScopeCode instanceof ScopeInterface) {
$resolverScopeCode = $resolverScopeCode->getCode();
}

if ($scopeCode == null) {
$scopeCode = $resolverScopeCode;
}

$this->resolvedScopeCodes[$scopeType][$scopeCode] = $resolverScopeCode;

return $resolverScopeCode;
}

Expand Down

0 comments on commit bc8f909

Please sign in to comment.