Skip to content

Commit 284288d

Browse files
committed
MAGE-848 Handle complexities of nested scoped configurations by accounting for website level overrides
1 parent 1ee39cd commit 284288d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Setup/Patch/Data/MigrateVirtualReplicaConfigPatch.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ public function migrateSetting(string $scope = ScopeConfigInterface::SCOPE_TYPE_
7070
return;
7171
}
7272

73-
// Replicate the global settings by turning on virtual replicas for all attributes
74-
$virtualizedSorts = $this->simulateFullVirtualReplicas($scope, $scopeId);
75-
7673
// Get all stores affected by this configuration
7774
$storeIds = $this->configChecker->getAffectedStoreIds(
7875
ConfigHelper::USE_VIRTUAL_REPLICA_ENABLED,
7976
$scope,
8077
$scopeId
8178
);
8279

80+
// Replicate the global settings by turning on virtual replicas for all attributes and initialize based on current scope
81+
$virtualizedSorts = $this->simulateFullVirtualReplicas($scope, $scopeId);
82+
8383
// Retrieve the sorting config
8484
foreach ($storeIds as $storeId) {
85+
// Get the store specific sorting configuration
86+
$virtualizedSorts = $this->simulateFullVirtualReplicas(ScopeInterface::SCOPE_STORES, $storeId);
87+
8588
$sortingIndices = $this->sortingTransformer->getSortingIndices($storeId, null, $virtualizedSorts);
8689

8790
$validator = $this->validatorFactory->create();
@@ -103,10 +106,16 @@ public function migrateSetting(string $scope = ScopeConfigInterface::SCOPE_TYPE_
103106
}
104107

105108
// If all is copacetic then save the new sorting config
106-
// Save to store scope if we are not already there or if a store scope override exists
109+
// Save to store scope if we are not already there and a store scope override exists
107110
if ($scope != ScopeInterface::SCOPE_STORES
108111
&& $this->configChecker->isSettingAppliedForScopeAndCode(ConfigHelper::SORTING_INDICES, ScopeInterface::SCOPE_STORES, $storeId)) {
109112
$this->configHelper->setSorting($virtualizedSorts, ScopeInterface::SCOPE_STORES, $storeId);
113+
// If not overridden at store level next check for website overrides
114+
} else if ($scope != ScopeInterface::SCOPE_WEBSITES) {
115+
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
116+
if ($this->configChecker->isSettingAppliedForScopeAndCode(ConfigHelper::SORTING_INDICES, ScopeInterface::SCOPE_WEBSITES, $websiteId)) {
117+
$this->configHelper->setSorting($virtualizedSorts, ScopeInterface::SCOPE_WEBSITES, $websiteId);
118+
}
110119
}
111120
}
112121

0 commit comments

Comments
 (0)