|
2 | 2 |
|
3 | 3 | namespace Algolia\AlgoliaSearch\Model\Backend;
|
4 | 4 |
|
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; |
8 | 7 | use Magento\Framework\App\Cache\TypeListInterface;
|
9 | 8 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
10 | 9 | use Magento\Framework\App\Config\Value;
|
|
13 | 12 | use Magento\Framework\Model\Context;
|
14 | 13 | use Magento\Framework\Model\ResourceModel\AbstractResource;
|
15 | 14 | use Magento\Framework\Registry;
|
16 |
| -use Magento\Store\Model\StoreManagerInterface; |
17 | 15 |
|
18 | 16 | class EnableCustomerGroups extends Value
|
19 | 17 | {
|
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 |
| - */ |
32 | 18 | 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 = [] |
43 | 28 | )
|
44 | 29 | {
|
45 | 30 | parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
|
46 | 31 | }
|
47 | 32 |
|
48 | 33 | /**
|
49 | 34 | * @return $this
|
50 |
| - * @throws AlgoliaException |
51 | 35 | * @throws NoSuchEntityException
|
52 | 36 | */
|
53 |
| - public function afterSave(): \Magento\Framework\App\Config\Value |
| 37 | + public function afterSave(): Value |
54 | 38 | {
|
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); |
69 | 51 | }
|
70 |
| - */ |
71 | 52 |
|
72 | 53 | return parent::afterSave();
|
73 | 54 | }
|
|
0 commit comments