Skip to content

Commit 89ea42e

Browse files
authored
Merge pull request #1449 from algolia/revert-1444-bugfix/MAGE-797
Revert "Duplicate Replica Issue one set is standard and another is virtual"
2 parents 9dd7972 + dd16d36 commit 89ea42e

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Helper/Entity/ProductHelper.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
463463

464464
// Managing Virtual Replica
465465
if ($this->configHelper->useVirtualReplica($storeId)) {
466-
$replicas = $this->handleVirtualReplica($replicas);
466+
$replicas = $this->handleVirtualReplica($replicas, $indexName);
467467
}
468468

469469
// Merge current replicas with sorting replicas to not delete A/B testing replica indices
@@ -1534,7 +1534,7 @@ public function productIsInStock($product, $storeId)
15341534
* @param $replica
15351535
* @return array
15361536
*/
1537-
public function handleVirtualReplica($replicas)
1537+
public function handleVirtualReplica($replicas, $indexName)
15381538
{
15391539
$virtualReplicaArray = [];
15401540
foreach ($replicas as $replica) {
@@ -1558,14 +1558,12 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
15581558
return $sortingIndex['name'];
15591559
}, $sortingIndices));
15601560
try {
1561-
$replicasFormated = $this->handleVirtualReplica($replicas);
1562-
$availableReplicaMatch = array_merge($replicasFormated, $replicas);
15631561
if ($this->configHelper->useVirtualReplica($storeId)) {
1564-
$replicas = $replicasFormated;
1562+
$replicas = $this->handleVirtualReplica($replicas, $indexName);
15651563
}
15661564
$currentSettings = $this->algoliaHelper->getSettings($indexName);
15671565
if (is_array($currentSettings) && array_key_exists('replicas', $currentSettings)) {
1568-
$replicasRequired = array_values(array_diff($currentSettings['replicas'], $availableReplicaMatch));
1566+
$replicasRequired = array_values(array_diff_assoc($currentSettings['replicas'], $replicas));
15691567
$this->algoliaHelper->setSettings($indexName, ['replicas' => $replicasRequired]);
15701568
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
15711569
$this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId);

Model/Backend/Sorts.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ public function afterSave()
7474
if ($this->isValueChanged()) {
7575
try{
7676
$oldValue = $this->serializer->unserialize($this->getOldValue());
77-
$updatedValue = $this->serializer->unserialize($this->getValue());
78-
$sortingAttributes = array_merge($oldValue, $updatedValue);
7977
$storeIds = array_keys($this->storeManager->getStores());
8078
foreach ($storeIds as $storeId) {
8179
$indexName = $this->helper->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId);
82-
$this->productHelper->handlingReplica($indexName, $storeId, $sortingAttributes);
80+
$this->productHelper->handlingReplica($indexName, $storeId, $oldValue);
8381
}
8482
} catch (AlgoliaException $e) {
8583
if ($e->getCode() !== 404) {

0 commit comments

Comments
 (0)