Skip to content

Commit 327bb2f

Browse files
committed
MAGE-839 Apply scoped replica state management to customer group enablement
1 parent b3e91eb commit 327bb2f

File tree

1 file changed

+24
-43
lines changed

1 file changed

+24
-43
lines changed

Model/Backend/EnableCustomerGroups.php

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace Algolia\AlgoliaSearch\Model\Backend;
44

5-
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
6-
use Algolia\AlgoliaSearch\Helper\Data;
7-
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
5+
use Algolia\AlgoliaSearch\Helper\Configuration\ConfigChecker;
6+
use Algolia\AlgoliaSearch\Registry\ReplicaState;
87
use Magento\Framework\App\Cache\TypeListInterface;
98
use Magento\Framework\App\Config\ScopeConfigInterface;
109
use Magento\Framework\App\Config\Value;
@@ -13,61 +12,43 @@
1312
use Magento\Framework\Model\Context;
1413
use Magento\Framework\Model\ResourceModel\AbstractResource;
1514
use Magento\Framework\Registry;
16-
use Magento\Store\Model\StoreManagerInterface;
1715

1816
class EnableCustomerGroups extends Value
1917
{
20-
/**
21-
* @param Context $context
22-
* @param Registry $registry
23-
* @param ScopeConfigInterface $config
24-
* @param TypeListInterface $cacheTypeList
25-
* @param StoreManagerInterface $storeManager
26-
* @param Data $helper
27-
* @param ProductHelper $productHelper
28-
* @param AbstractResource|null $resource
29-
* @param AbstractDb|null $resourceCollection
30-
* @param array $data
31-
*/
3218
public function __construct(
33-
Context $context,
34-
Registry $registry,
35-
ScopeConfigInterface $config,
36-
TypeListInterface $cacheTypeList,
37-
protected StoreManagerInterface $storeManager,
38-
protected Data $helper,
39-
protected ProductHelper $productHelper,
40-
AbstractResource $resource = null,
41-
AbstractDb $resourceCollection = null,
42-
array $data = []
19+
Context $context,
20+
Registry $registry,
21+
ScopeConfigInterface $config,
22+
TypeListInterface $cacheTypeList,
23+
protected ReplicaState $replicaState,
24+
protected ConfigChecker $configChecker,
25+
AbstractResource $resource = null,
26+
AbstractDb $resourceCollection = null,
27+
array $data = []
4328
)
4429
{
4530
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
4631
}
4732

4833
/**
4934
* @return $this
50-
* @throws AlgoliaException
5135
* @throws NoSuchEntityException
5236
*/
53-
public function afterSave(): \Magento\Framework\App\Config\Value
37+
public function afterSave(): Value
5438
{
55-
// TODO: Determine if this action should be performed in the event of customer group pricing enablement
56-
/*
57-
if ($this->isValueChanged()) {
58-
try {
59-
$storeIds = array_keys($this->storeManager->getStores());
60-
foreach ($storeIds as $storeId) {
61-
$indexName = $this->helper->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId);
62-
$this->productHelper->handlingReplica($indexName, $storeId);
63-
}
64-
} catch (AlgoliaException $e) {
65-
if ($e->getCode() !== 404) {
66-
throw $e;
67-
}
68-
}
39+
$storeIds = $this->configChecker->getAffectedStoreIds(
40+
$this->getPath(),
41+
$this->getScope(),
42+
$this->getScopeId()
43+
);
44+
45+
foreach ($storeIds as $storeId) {
46+
$this->replicaState->setChangeState(
47+
$this->isValueChanged()
48+
? ReplicaState::REPLICA_STATE_CHANGED
49+
: ReplicaState::REPLICA_STATE_UNCHANGED,
50+
$storeId);
6951
}
70-
*/
7152

7253
return parent::afterSave();
7354
}

0 commit comments

Comments
 (0)