@@ -452,12 +452,11 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
452
452
* Handle replicas
453
453
*/
454
454
$ sortingIndices = $ this ->configHelper ->getSortingIndices ($ indexName , $ storeId );
455
-
456
455
$ replicas = [];
457
456
458
457
if ($ this ->configHelper ->isInstantEnabled ($ storeId )) {
459
458
$ replicas = array_values (array_map (function ($ sortingIndex ) {
460
- return $ sortingIndex ['name ' ];
459
+ return [ $ sortingIndex ['name ' ], $ sortingIndex [ ' virtualReplica ' ] ];
461
460
}, $ sortingIndices ));
462
461
}
463
462
@@ -483,25 +482,23 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
483
482
$ this ->logger ->log ('Setting replicas to " ' . $ indexName . '" index. ' );
484
483
$ this ->logger ->log ('Replicas: ' . json_encode ($ replicas ));
485
484
$ setReplicasTaskId = $ this ->algoliaHelper ->getLastTaskId ();
486
-
487
- if (!$ this ->configHelper ->useVirtualReplica ($ storeId )) {
488
- foreach ($ sortingIndices as $ values ) {
489
- $ replicaName = $ values ['name ' ];
490
- $ indexSettings ['ranking ' ] = $ values ['ranking ' ];
491
- $ this ->algoliaHelper ->setSettings ($ replicaName , $ indexSettings , false , true );
492
- $ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
493
- $ this ->logger ->log ('Settings: ' . json_encode ($ indexSettings ));
494
- }
495
- } else {
496
- foreach ($ sortingIndices as $ values ) {
485
+ foreach ($ sortingIndices as $ values ) {
486
+ if ($ values ['virtualReplica ' ]) {
497
487
$ replicaName = $ values ['name ' ];
498
488
array_unshift ($ customRanking , $ values ['ranking ' ][0 ]);
499
489
$ replicaSetting ['customRanking ' ] = $ customRanking ;
500
490
$ this ->algoliaHelper ->setSettings ($ replicaName , $ replicaSetting , false , false );
501
491
$ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
502
492
$ this ->logger ->log ('Settings: ' . json_encode ($ replicaSetting ));
493
+ } else {
494
+ $ replicaName = $ values ['name ' ];
495
+ $ indexSettings ['ranking ' ] = $ values ['ranking ' ];
496
+ $ this ->algoliaHelper ->setSettings ($ replicaName , $ indexSettings , false , true );
497
+ $ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
498
+ $ this ->logger ->log ('Settings: ' . json_encode ($ indexSettings ));
503
499
}
504
500
}
501
+
505
502
} else {
506
503
$ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => []]);
507
504
$ this ->logger ->log ('Removing replicas from " ' . $ indexName . '" index ' );
@@ -574,7 +571,7 @@ public function getObject(Product $product)
574
571
);
575
572
576
573
$ defaultData = $ transport ->getData ();
577
-
574
+
578
575
$ visibility = $ product ->getVisibility ();
579
576
580
577
$ visibleInCatalog = $ this ->visibility ->getVisibleInCatalogIds ();
@@ -1056,7 +1053,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P
1056
1053
}
1057
1054
1058
1055
$ attributeResource = $ attributeResource ->setData ('store_id ' , $ product ->getStoreId ());
1059
-
1056
+
1060
1057
$ value = $ product ->getData ($ attributeName );
1061
1058
1062
1059
if ($ value !== null ) {
@@ -1538,9 +1535,13 @@ public function handleVirtualReplica($replicas)
1538
1535
{
1539
1536
$ virtualReplicaArray = [];
1540
1537
foreach ($ replicas as $ replica ) {
1541
- $ virtualReplicaArray [] = 'virtual( ' . $ replica . ') ' ;
1538
+ if ($ replica [1 ]) {
1539
+ $ replicaArray [] = 'virtual( ' . $ replica [0 ] . ') ' ;
1540
+ } else {
1541
+ $ replicaArray [] = $ replica [0 ];
1542
+ }
1542
1543
}
1543
- return $ virtualReplicaArray ;
1544
+ return $ replicaArray ;
1544
1545
}
1545
1546
1546
1547
/**
@@ -1555,8 +1556,9 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
1555
1556
$ sortingIndices = $ this ->configHelper ->getSortingIndices ($ indexName , $ storeId , null , $ sortingAttribute );
1556
1557
if ($ this ->configHelper ->isInstantEnabled ($ storeId )) {
1557
1558
$ replicas = array_values (array_map (function ($ sortingIndex ) {
1558
- return $ sortingIndex ['name ' ];
1559
+ return [ $ sortingIndex ['name ' ], $ sortingIndex [ ' virtualReplica ' ] ];
1559
1560
}, $ sortingIndices ));
1561
+
1560
1562
try {
1561
1563
$ replicasFormated = $ this ->handleVirtualReplica ($ replicas );
1562
1564
$ availableReplicaMatch = array_merge ($ replicasFormated , $ replicas );
@@ -1584,4 +1586,4 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
1584
1586
}
1585
1587
return true ;
1586
1588
}
1587
- }
1589
+ }
0 commit comments