Skip to content

Commit 3b54b49

Browse files
authored
Merge pull request #1444 from algolia/bugfix/MAGE-797
Duplicate Replica Issue one set is standard and another is virtual
2 parents da3f69d + 2e28513 commit 3b54b49

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Helper/Entity/ProductHelper.php

Lines changed: 6 additions & 4 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, $indexName);
466+
$replicas = $this->handleVirtualReplica($replicas);
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, $indexName)
1537+
public function handleVirtualReplica($replicas)
15381538
{
15391539
$virtualReplicaArray = [];
15401540
foreach ($replicas as $replica) {
@@ -1558,12 +1558,14 @@ 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);
15611563
if ($this->configHelper->useVirtualReplica($storeId)) {
1562-
$replicas = $this->handleVirtualReplica($replicas, $indexName);
1564+
$replicas = $replicasFormated;
15631565
}
15641566
$currentSettings = $this->algoliaHelper->getSettings($indexName);
15651567
if (is_array($currentSettings) && array_key_exists('replicas', $currentSettings)) {
1566-
$replicasRequired = array_values(array_diff_assoc($currentSettings['replicas'], $replicas));
1568+
$replicasRequired = array_values(array_diff($currentSettings['replicas'], $availableReplicaMatch));
15671569
$this->algoliaHelper->setSettings($indexName, ['replicas' => $replicasRequired]);
15681570
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
15691571
$this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId);

Model/Backend/Sorts.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ 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);
7779
$storeIds = array_keys($this->storeManager->getStores());
7880
foreach ($storeIds as $storeId) {
7981
$indexName = $this->helper->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId);
80-
$this->productHelper->handlingReplica($indexName, $storeId, $oldValue);
82+
$this->productHelper->handlingReplica($indexName, $storeId, $sortingAttributes);
8183
}
8284
} catch (AlgoliaException $e) {
8385
if ($e->getCode() !== 404) {

0 commit comments

Comments
 (0)