diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index d8e5db0aaa47f..6a88057de3159 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -217,7 +217,10 @@ protected function _loadScopedData() } $this->_scopePriorityScheme[] = $scope; - $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; + // Normalize cache ID by sorting scopes - ensures consistent ID regardless of processing order + $sortedScheme = array_values($this->_scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->_cacheId; $configData = $this->configLoader->load($cacheId); if ($configData) { diff --git a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php index 0153ee92a8062..426674b3b41b7 100644 --- a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php +++ b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php @@ -90,10 +90,17 @@ public function write(array $scopes): void foreach ($scopes as $scope) { $this->scopeConfig->setCurrentScope($scope); if (false === isset($this->loadedScopes[$scope])) { - if (false === in_array($scope, $this->scopePriorityScheme, true)) { - $this->scopePriorityScheme[] = $scope; + // Match PluginList::_loadScopedData() behavior - move scope to end + // This ensures cache IDs match between compile-time and runtime + $index = array_search($scope, $this->scopePriorityScheme, true); + if ($index !== false) { + unset($this->scopePriorityScheme[$index]); } - $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; + $this->scopePriorityScheme[] = $scope; + // Normalize cache ID by sorting scopes - ensures consistent ID regardless of processing order + $sortedScheme = array_values($this->scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->cacheId; [ $virtualTypes, $this->scopePriorityScheme, diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 22a4f5530c232..72c2586e1b0ec 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -44,12 +44,8 @@ public function __construct( public function doOperation() { $scopes = $this->scopeConfig->getAllScopes(); - // remove primary scope for production mode as it is only called in developer mode - $scopes = array_diff($scopes, ['primary']); - - // sort configuration to have it in the same order on every build - ksort($scopes); - + // Cache IDs are now normalized (sorted) in PluginListGenerator::write() + // so processing order no longer affects cache ID generation $this->configWriter->write($scopes); }