Skip to content

Commit 0cce72f

Browse files
authored
Update Conflicts
1 parent 5cf7bde commit 0cce72f

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

Helper/Entity/ProductHelper.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,14 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
456456

457457
if ($this->configHelper->isInstantEnabled($storeId)) {
458458
$replicas = array_values(array_map(function ($sortingIndex) {
459-
return [$sortingIndex['name'],$sortingIndex['virtualReplica']];
459+
rreturn $sortingIndex['name'];
460460
}, $sortingIndices));
461461
}
462462

463463
// Managing Virtual Replica
464-
$replicas = $this->handleVirtualReplica($replicas, $indexName, $storeId);
464+
if ($this->configHelper->useVirtualReplica($storeId)) {
465+
$replicas = $this->handleVirtualReplica($replicas, $indexName);
466+
}
465467

466468
// Merge current replicas with sorting replicas to not delete A/B testing replica indices
467469
try {
@@ -480,23 +482,24 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
480482
$this->logger->log('Setting replicas to "' . $indexName . '" index.');
481483
$this->logger->log('Replicas: ' . json_encode($replicas));
482484
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
483-
foreach ($sortingIndices as $values) {
484-
if ($values['virtualReplica']) {
485+
if (!$this->configHelper->useVirtualReplica($storeId)) {
486+
foreach ($sortingIndices as $values) {
487+
$replicaName = $values['name'];
488+
$indexSettings['ranking'] = $values['ranking'];
489+
$this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true);
490+
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
491+
$this->logger->log('Settings: ' . json_encode($indexSettings));
492+
}
493+
} else {
494+
foreach ($sortingIndices as $values) {
485495
$replicaName = $values['name'];
486496
array_unshift($customRanking, $values['ranking'][0]);
487497
$replicaSetting['customRanking'] = $customRanking;
488498
$this->algoliaHelper->setSettings($replicaName, $replicaSetting, false, false);
489499
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
490500
$this->logger->log('Settings: ' . json_encode($replicaSetting));
491-
} else {
492-
$replicaName = $values['name'];
493-
$indexSettings['ranking'] = $values['ranking'];
494-
$this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true);
495-
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
496-
$this->logger->log('Settings: ' . json_encode($indexSettings));
497501
}
498502
}
499-
500503
} else {
501504
$this->algoliaHelper->setSettings($indexName, ['replicas' => []]);
502505
$this->logger->log('Removing replicas from "' . $indexName . '" index');
@@ -1525,17 +1528,13 @@ public function productIsInStock($product, $storeId)
15251528
* @param $replica
15261529
* @return array
15271530
*/
1528-
public function handleVirtualReplica($replicas, $indexName, $storeId)
1531+
public function handleVirtualReplica($replicas, $indexName)
15291532
{
15301533
$virtualReplicaArray = [];
15311534
foreach ($replicas as $replica) {
1532-
if ($replica[1]) {
1533-
$replicaArray[] = 'virtual(' . $replica[0] . ')';
1534-
} else {
1535-
$replicaArray[] = $replica[0];
1536-
}
1535+
$virtualReplicaArray[] = 'virtual(' . $replica . ')';
15371536
}
1538-
return $replicaArray;
1537+
return $virtualReplicaArray;
15391538
}
15401539

15411540
/**
@@ -1553,14 +1552,12 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
15531552
return $sortingIndex['name'];
15541553
}, $sortingIndices));
15551554
try {
1556-
$replicasFormated = $this->handleVirtualReplica($replicas);
1557-
$availableReplicaMatch = array_merge($replicasFormated, $replicas);
15581555
if ($this->configHelper->useVirtualReplica($storeId)) {
1559-
$replicas = $replicasFormated;
1556+
$replicas = $this->handleVirtualReplica($replicas, $indexName);
15601557
}
15611558
$currentSettings = $this->algoliaHelper->getSettings($indexName);
15621559
if (is_array($currentSettings) && array_key_exists('replicas', $currentSettings)) {
1563-
$replicasRequired = array_values(array_diff($currentSettings['replicas'], $availableReplicaMatch));
1560+
$replicasRequired = array_values(array_diff_assoc($currentSettings['replicas'], $replicas));
15641561
$this->algoliaHelper->setSettings($indexName, ['replicas' => $replicasRequired]);
15651562
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
15661563
$this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId);
@@ -1579,4 +1576,4 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
15791576
}
15801577
return true;
15811578
}
1582-
}
1579+
}

0 commit comments

Comments
 (0)