Skip to content

Commit 114e078

Browse files
committed
MAGE-838 Add reversion for customer group enablement
1 parent e42ed35 commit 114e078

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

Helper/ConfigHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,16 @@ public function isCustomerGroupsEnabled($storeId = null)
11601160
return $this->configInterface->isSetFlag(self::CUSTOMER_GROUPS_ENABLE, ScopeInterface::SCOPE_STORE, $storeId);
11611161
}
11621162

1163+
public function setCustomerGroupsEnabled(bool $val, ?string $scope = null, ?int $scopeId = null): void
1164+
{
1165+
$this->configWriter->save(
1166+
self::CUSTOMER_GROUPS_ENABLE,
1167+
$val ? '1' : '0',
1168+
$scope,
1169+
$scopeId
1170+
);
1171+
}
1172+
11631173
/**
11641174
* @param $storeId
11651175
* @return bool

Model/Backend/EnableCustomerGroups.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function __construct(
3636
*/
3737
public function afterSave(): Value
3838
{
39+
$this->replicaState->setAppliedScope($this->getScope(), $this->getScopeId());
40+
$this->replicaState->setCustomerGroupsEnabled((bool) $this->getValue());
41+
3942
$storeIds = $this->configChecker->getAffectedStoreIds(
4043
$this->getPath(),
4144
$this->getScope(),

Model/Backend/Sorts.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public function __construct(
4848
*/
4949
public function afterSave(): \Magento\Framework\App\Config\Value
5050
{
51-
// Save context of the admin operation for possible state reversion
52-
$this->replicaState->setParentScope($this->getScope());
53-
$this->replicaState->setParentScopeId($this->getScopeId());
51+
$this->replicaState->setAppliedScope($this->getScope(), $this->getScopeId());
5452

5553
$storeIds = $this->configChecker->getAffectedStoreIds(
5654
$this->getPath(),

Model/Product/ReplicaManager.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ protected function revertReplicaConfig(int $storeId): bool
303303
return true;
304304
}
305305

306+
if ($this->replicaState->wereCustomerGroupsEnabled()) {
307+
$this->configHelper->setCustomerGroupsEnabled(
308+
false,
309+
$this->replicaState->getParentScope(),
310+
$this->replicaState->getParentScopeId());
311+
return true;
312+
}
313+
306314
return false;
307315
}
308316

Registry/ReplicaState.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,34 @@ class ReplicaState
1717
private ?string $_parentScope = null;
1818
private ?int $_parentScopeId = null;
1919

20+
private bool $_customerGroupsEnabled = false;
21+
22+
/**
23+
* Save context of the original admin operation
24+
* This is considered the "parent" scope.
25+
* This is different from the affected store IDs for the applied/parent scope
26+
* Retaining this is necessary for potential state reversion on error because while changes are persisted
27+
* to Algolia indices for each store, the idea of default / website scope is a Magento only concept.
28+
*
29+
* @param string $scope
30+
* @param int $scopeId
31+
* @return void
32+
*/
33+
public function setAppliedScope(string $scope, int $scopeId): void {
34+
$this->_parentScope = $scope;
35+
$this->_parentScopeId = $scopeId;
36+
}
37+
2038
public function getParentScope(): ?string
2139
{
2240
return $this->_parentScope;
2341
}
2442

25-
public function setParentScope(string $scope) {
26-
$this->_parentScope = $scope;
27-
}
28-
2943
public function getParentScopeId(): ?int
3044
{
3145
return $this->_parentScopeId;
3246
}
3347

34-
public function setParentScopeId(int $scopeId) {
35-
$this->_parentScopeId = $scopeId;
36-
}
37-
3848
public function getOriginalSortConfiguration(int $storeId): array
3949
{
4050
return $this->_scopeConfigurationOld[$storeId] ?? [];
@@ -55,7 +65,8 @@ public function setUpdatedSortConfiguration(array $updatedSortConfiguration, int
5565
$this->_scopeConfigurationNew[$storeId] = $updatedSortConfiguration;
5666
}
5767

58-
protected function hasConfigDataToCompare(int $storeId) {
68+
protected function hasConfigDataToCompare(int $storeId): bool
69+
{
5970
return isset($this->_scopeConfigurationOld[$storeId])
6071
&& isset($this->_scopeConfigurationNew[$storeId]);
6172
}
@@ -79,4 +90,14 @@ public function setChangeState(int $state, int $storeId): void
7990
$this->_scopeState[$storeId] = $state;
8091
}
8192

93+
public function wereCustomerGroupsEnabled(): bool
94+
{
95+
return $this->_customerGroupsEnabled;
96+
}
97+
98+
public function setCustomerGroupsEnabled(bool $customerGroupsEnabled): void
99+
{
100+
$this->_customerGroupsEnabled = $customerGroupsEnabled;
101+
}
102+
82103
}

0 commit comments

Comments
 (0)