Skip to content

Commit b25bbee

Browse files
committed
MAGE-848 Fix bug in config checker where intermediary (parent) scopes were not correctly compared
1 parent 733a460 commit b25bbee

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Helper/Configuration/ConfigChecker.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717
) {}
1818

1919
/**
20-
* Is a scoped value different from the default?
20+
* Is a scoped value different from its higher scope?
2121
* @param string $path
2222
* @param string $scope
2323
* @param mixed $code
@@ -26,7 +26,11 @@ public function __construct(
2626
public function isSettingAppliedForScopeAndCode(string $path, string $scope, mixed $code): bool
2727
{
2828
$value = $this->scopeConfig->getValue($path, $scope, $code);
29-
$defaultValue = $this->scopeConfig->getValue($path);
29+
if ($scope === ScopeInterface::SCOPE_STORES) {
30+
$defaultValue = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_WEBSITES, $this->storeManager->getStore($code)->getWebsiteId());
31+
} else {
32+
$defaultValue = $this->scopeConfig->getValue($path);
33+
}
3034
return ($value !== $defaultValue);
3135
}
3236

@@ -57,28 +61,30 @@ protected function isStoreSettingOverridingWebsite(string $path, mixed $websiteI
5761
*/
5862
public function checkAndApplyAllScopes(string $path, callable $callback, bool $includeDefault = true): void
5963
{
60-
// First update all the possible scoped configurations
61-
foreach ($this->storeManager->getWebsites() as $website) {
64+
// Progressively increase scope so that override comparisons work as expected
65+
// Start with most specific (store scope) first
66+
foreach ($this->storeManager->getStores() as $store) {
6267
if ($this->isSettingAppliedForScopeAndCode(
6368
$path,
64-
ScopeInterface::SCOPE_WEBSITES,
65-
$website->getId()
69+
ScopeInterface::SCOPE_STORES,
70+
$store->getId()
6671
)) {
67-
$callback(ScopeInterface::SCOPE_WEBSITES, $website->getId());
72+
$callback(ScopeInterface::SCOPE_STORES, $store->getId());
6873
}
6974
}
7075

71-
foreach ($this->storeManager->getStores() as $store) {
76+
// Websites
77+
foreach ($this->storeManager->getWebsites() as $website) {
7278
if ($this->isSettingAppliedForScopeAndCode(
7379
$path,
74-
ScopeInterface::SCOPE_STORES,
75-
$store->getId()
80+
ScopeInterface::SCOPE_WEBSITES,
81+
$website->getId()
7682
)) {
77-
$callback(ScopeInterface::SCOPE_STORES, $store->getId());
83+
$callback(ScopeInterface::SCOPE_WEBSITES, $website->getId());
7884
}
7985
}
8086

81-
// Update the default configuration *last* so that initial scope comparisons work as expected
87+
// Update the default configuration *last* so that earlier scope comparisons work as expected
8288
if ($includeDefault) {
8389
$callback(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
8490
}

0 commit comments

Comments
 (0)