@@ -452,19 +452,16 @@ 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
464
463
// Managing Virtual Replica
465
- if ($ this ->configHelper ->useVirtualReplica ($ storeId )) {
466
- $ replicas = $ this ->handleVirtualReplica ($ replicas , $ indexName );
467
- }
464
+ $ replicas = $ this ->handleVirtualReplica ($ replicas , $ indexName , $ storeId );
468
465
469
466
// Merge current replicas with sorting replicas to not delete A/B testing replica indices
470
467
try {
@@ -483,25 +480,23 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
483
480
$ this ->logger ->log ('Setting replicas to " ' . $ indexName . '" index. ' );
484
481
$ this ->logger ->log ('Replicas: ' . json_encode ($ replicas ));
485
482
$ 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 ) {
483
+ foreach ($ sortingIndices as $ values ) {
484
+ if ($ values ['virtualReplica ' ]) {
497
485
$ replicaName = $ values ['name ' ];
498
486
array_unshift ($ customRanking , $ values ['ranking ' ][0 ]);
499
487
$ replicaSetting ['customRanking ' ] = $ customRanking ;
500
488
$ this ->algoliaHelper ->setSettings ($ replicaName , $ replicaSetting , false , false );
501
489
$ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
502
490
$ 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 ));
503
497
}
504
498
}
499
+
505
500
} else {
506
501
$ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => []]);
507
502
$ this ->logger ->log ('Removing replicas from " ' . $ indexName . '" index ' );
@@ -574,7 +569,6 @@ public function getObject(Product $product)
574
569
);
575
570
576
571
$ defaultData = $ transport ->getData ();
577
-
578
572
$ visibility = $ product ->getVisibility ();
579
573
580
574
$ visibleInCatalog = $ this ->visibility ->getVisibleInCatalogIds ();
@@ -1054,7 +1048,6 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P
1054
1048
}
1055
1049
1056
1050
$ attributeResource = $ attributeResource ->setData ('store_id ' , $ product ->getStoreId ());
1057
-
1058
1051
$ value = $ product ->getData ($ attributeName );
1059
1052
1060
1053
if ($ value !== null ) {
@@ -1066,7 +1059,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P
1066
1059
}
1067
1060
1068
1061
$ type = $ product ->getTypeId ();
1069
- if ($ type !== 'configurable ' && $ type !== 'grouped ' && $ type !== 'bundle ' ) {
1062
+ if ($ type !== 'configurable ' && $ type !== 'grouped ' && $ type !== 'bundle ' && $ attributeName != ' test ' ) {
1070
1063
continue ;
1071
1064
}
1072
1065
@@ -1229,7 +1222,7 @@ protected function addNonNullValue(
1229
1222
$ value = $ attributeResource ->getFrontend ()->getValue ($ product );
1230
1223
}
1231
1224
1232
- if ($ value ) {
1225
+ if ($ value !== null ) {
1233
1226
$ customData [$ attribute ['attribute ' ]] = $ value ;
1234
1227
}
1235
1228
@@ -1532,13 +1525,17 @@ public function productIsInStock($product, $storeId)
1532
1525
* @param $replica
1533
1526
* @return array
1534
1527
*/
1535
- public function handleVirtualReplica ($ replicas , $ indexName )
1528
+ public function handleVirtualReplica ($ replicas , $ indexName, $ storeId )
1536
1529
{
1537
1530
$ virtualReplicaArray = [];
1538
1531
foreach ($ replicas as $ replica ) {
1539
- $ virtualReplicaArray [] = 'virtual( ' . $ replica . ') ' ;
1532
+ if ($ replica [1 ]) {
1533
+ $ replicaArray [] = 'virtual( ' . $ replica [0 ] . ') ' ;
1534
+ } else {
1535
+ $ replicaArray [] = $ replica [0 ];
1536
+ }
1540
1537
}
1541
- return $ virtualReplicaArray ;
1538
+ return $ replicaArray ;
1542
1539
}
1543
1540
1544
1541
/**
@@ -1553,12 +1550,12 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
1553
1550
$ sortingIndices = $ this ->configHelper ->getSortingIndices ($ indexName , $ storeId , null , $ sortingAttribute );
1554
1551
if ($ this ->configHelper ->isInstantEnabled ($ storeId )) {
1555
1552
$ replicas = array_values (array_map (function ($ sortingIndex ) {
1556
- return $ sortingIndex ['name ' ];
1553
+ return [ $ sortingIndex ['name ' ], $ sortingIndex [ ' virtualReplica ' ] ];
1557
1554
}, $ sortingIndices ));
1555
+
1558
1556
try {
1559
- if ($ this ->configHelper ->useVirtualReplica ($ storeId )) {
1560
- $ replicas = $ this ->handleVirtualReplica ($ replicas , $ indexName );
1561
- }
1557
+ $ replicas = $ this ->handleVirtualReplica ($ replicas , $ indexName , $ storeId );
1558
+
1562
1559
$ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
1563
1560
if (is_array ($ currentSettings ) && array_key_exists ('replicas ' , $ currentSettings )) {
1564
1561
$ replicasRequired = array_values (array_diff_assoc ($ currentSettings ['replicas ' ], $ replicas ));
@@ -1580,4 +1577,4 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
1580
1577
}
1581
1578
return true ;
1582
1579
}
1583
- }
1580
+ }
0 commit comments