@@ -17,7 +17,7 @@ public function __construct(
17
17
) {}
18
18
19
19
/**
20
- * Is a scoped value different from the default ?
20
+ * Is a scoped value different from its higher scope ?
21
21
* @param string $path
22
22
* @param string $scope
23
23
* @param mixed $code
@@ -26,7 +26,11 @@ public function __construct(
26
26
public function isSettingAppliedForScopeAndCode (string $ path , string $ scope , mixed $ code ): bool
27
27
{
28
28
$ 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
+ }
30
34
return ($ value !== $ defaultValue );
31
35
}
32
36
@@ -57,28 +61,30 @@ protected function isStoreSettingOverridingWebsite(string $path, mixed $websiteI
57
61
*/
58
62
public function checkAndApplyAllScopes (string $ path , callable $ callback , bool $ includeDefault = true ): void
59
63
{
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 ) {
62
67
if ($ this ->isSettingAppliedForScopeAndCode (
63
68
$ path ,
64
- ScopeInterface::SCOPE_WEBSITES ,
65
- $ website ->getId ()
69
+ ScopeInterface::SCOPE_STORES ,
70
+ $ store ->getId ()
66
71
)) {
67
- $ callback (ScopeInterface::SCOPE_WEBSITES , $ website ->getId ());
72
+ $ callback (ScopeInterface::SCOPE_STORES , $ store ->getId ());
68
73
}
69
74
}
70
75
71
- foreach ($ this ->storeManager ->getStores () as $ store ) {
76
+ // Websites
77
+ foreach ($ this ->storeManager ->getWebsites () as $ website ) {
72
78
if ($ this ->isSettingAppliedForScopeAndCode (
73
79
$ path ,
74
- ScopeInterface::SCOPE_STORES ,
75
- $ store ->getId ()
80
+ ScopeInterface::SCOPE_WEBSITES ,
81
+ $ website ->getId ()
76
82
)) {
77
- $ callback (ScopeInterface::SCOPE_STORES , $ store ->getId ());
83
+ $ callback (ScopeInterface::SCOPE_WEBSITES , $ website ->getId ());
78
84
}
79
85
}
80
86
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
82
88
if ($ includeDefault ) {
83
89
$ callback (ScopeConfigInterface::SCOPE_TYPE_DEFAULT );
84
90
}
0 commit comments