Skip to content

Commit e162a63

Browse files
authored
Merge pull request #1643 from algolia/release/3.14.3
3.14.3 to main
2 parents 499aa68 + fd6c4cb commit e162a63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2133
-348
lines changed

Block/Algolia.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
1111
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
1212
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
13+
use Algolia\AlgoliaSearch\Model\LandingPage as LandingPageModel;
1314
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
1415
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
1516
use Algolia\AlgoliaSearch\Service\Product\SortingTransformer;
@@ -215,7 +216,7 @@ protected function getAddToCartUrl($additional = []): string
215216
return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
216217
}
217218

218-
protected function getCurrentLandingPage(): LandingPage|null|false
219+
protected function getCurrentLandingPage(): LandingPageModel|null|false
219220
{
220221
$landingPageId = $this->getRequest()->getParam('landing_page_id');
221222
if (!$landingPageId) {

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# CHANGE LOG
22

3+
## 3.14.3
4+
5+
### Updates
6+
- Updated PHP client version in the composer file
7+
- Tests: added new integration scenarios including multi-stores ones.
8+
9+
### Bug Fixes
10+
- Fixed landing page typing error
11+
- Improved query method for alternate root categories - Thank you @igorfigueiredogen
12+
- Fixed an error where a missing prefix can throw errors with strong types added to ConfigHelper
13+
- Fixed an error where stale cache data was preventing ranking applied on replica
14+
- Fixed reindexing issue with NeuralSearch
15+
- Tests : Fixed current integration tests
16+
317
## 3.14.2
418

519
### Updates

Console/Command/ReplicaSyncCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
1212
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
1313
use Algolia\AlgoliaSearch\Service\StoreNameFetcher;
14-
use Magento\Framework\App\State;
14+
use Magento\Framework\App\State as AppState;
1515
use Magento\Framework\Console\Cli;
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\Exception\NoSuchEntityException;
@@ -27,12 +27,12 @@ public function __construct(
2727
protected ReplicaManagerInterface $replicaManager,
2828
protected ProductHelper $productHelper,
2929
protected StoreManagerInterface $storeManager,
30-
State $state,
30+
AppState $appState,
3131
StoreNameFetcher $storeNameFetcher,
3232
?string $name = null
3333
)
3434
{
35-
parent::__construct($state, $storeNameFetcher, $name);
35+
parent::__construct($appState, $storeNameFetcher, $name);
3636
}
3737

3838
protected function getReplicaCommandName(): string

Helper/AlgoliaHelper.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Algolia\AlgoliaSearch\Configuration\SearchConfig;
77
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
88
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
9+
use Algolia\AlgoliaSearch\Model\Search\SearchRulesResponse;
910
use Algolia\AlgoliaSearch\Response\AbstractResponse;
1011
use Algolia\AlgoliaSearch\Response\BatchIndexingResponse;
1112
use Algolia\AlgoliaSearch\Response\MultiResponse;
@@ -299,7 +300,7 @@ public function moveIndex(string $fromIndexName, string $toIndexName): void
299300
'destination' => $toIndexName
300301
]
301302
);
302-
self::setLastOperationInfo($fromIndexName, $response);
303+
self::setLastOperationInfo($toIndexName, $response);
303304
}
304305

305306
/**
@@ -360,6 +361,10 @@ public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')
360361

361362
$removes = ['slaves', 'replicas', 'decompoundedAttributes'];
362363

364+
if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
365+
$removes[] = 'mode';
366+
}
367+
363368
if (isset($settings['attributesToIndex'])) {
364369
$settings['searchableAttributes'] = $settings['attributesToIndex'];
365370
unset($settings['attributesToIndex']);
@@ -453,6 +458,19 @@ public function saveRule(array $rule, string $indexName, bool $forwardToReplicas
453458
self::setLastOperationInfo($indexName, $res);
454459
}
455460

461+
/**
462+
* @param string $indexName
463+
* @param array $rules
464+
* @param bool $forwardToReplicas
465+
* @return void
466+
*/
467+
public function saveRules(string $indexName, array $rules, bool $forwardToReplicas = false): void
468+
{
469+
$res = $this->client->saveRules($indexName, $rules, $forwardToReplicas);
470+
471+
self::setLastOperationInfo($indexName, $res);
472+
}
473+
456474

457475
/**
458476
* @param string $indexName
@@ -521,6 +539,21 @@ public function copyQueryRules(string $fromIndexName, string $toIndexName): void
521539
self::setLastOperationInfo($fromIndexName, $response);
522540
}
523541

542+
/**
543+
* @param string $indexName
544+
* @param array|null $searchRulesParams
545+
*
546+
* @return SearchRulesResponse|mixed[]
547+
*
548+
* @throws AlgoliaException
549+
*/
550+
public function searchRules(string $indexName, array$searchRulesParams = null)
551+
{
552+
$this->checkClient(__FUNCTION__);
553+
554+
return $this->client->searchRules($indexName, $searchRulesParams);
555+
}
556+
524557
/**
525558
* @param $methodName
526559
* @return void

Helper/ConfigHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function getAutocompleteSections($storeId = null)
446446
}
447447

448448
protected function serialize(array $value): string {
449-
return $this->serializer->serialize($value);
449+
return $this->serializer->serialize($value) ?: '';
450450
}
451451

452452
/**
@@ -1157,7 +1157,7 @@ public function getRawSortingValue(?int $storeId = null): string
11571157
* @param int|null $scopeId
11581158
* @return void
11591159
*/
1160-
public function setSorting(array $sorting, ?string $scope = null, ?int $scopeId = null): void
1160+
public function setSorting(array $sorting, string $scope = Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ?int $scopeId = null): void
11611161
{
11621162
$this->configWriter->save(
11631163
self::SORTING_INDICES,
@@ -1242,7 +1242,7 @@ public function getSearchOnlyAPIKey($storeId = null)
12421242
*/
12431243
public function getIndexPrefix(int $storeId = null): string
12441244
{
1245-
return $this->configInterface->getValue(self::INDEX_PREFIX, ScopeInterface::SCOPE_STORE, $storeId);
1245+
return (string) $this->configInterface->getValue(self::INDEX_PREFIX, ScopeInterface::SCOPE_STORE, $storeId);
12461246
}
12471247

12481248
/**

Helper/Entity/CategoryHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getCategoryCollectionQuery($storeId, $categoryIds = null)
125125
{
126126
/** @var \Magento\Store\Model\Store $store */
127127
$store = $this->storeManager->getStore($storeId);
128-
$storeRootCategoryPath = sprintf('%d/%d', $this->getRootCategoryId(), $store->getRootCategoryId());
128+
$storeRootCategoryPath = sprintf('%d/%d/', $this->getRootCategoryId(), $store->getRootCategoryId());
129129

130130
$unserializedCategorysAttrs = $this->getAdditionalAttributes($storeId);
131131
$additionalAttr = array_column($unserializedCategorysAttrs, 'attribute');

Helper/Entity/PageHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getPages($storeId, array $pageIds = null)
5959
$magentoPages->addFieldToFilter('page_id', ['in' => $pageIds]);
6060
}
6161

62-
$excludedPages = $this->getExcludedPageIds();
62+
$excludedPages = $this->getExcludedPageIds($storeId);
6363
if (count($excludedPages)) {
6464
$magentoPages->addFieldToFilter('identifier', ['nin' => $excludedPages]);
6565
}
@@ -116,9 +116,9 @@ public function getPages($storeId, array $pageIds = null)
116116
return $pages;
117117
}
118118

119-
public function getExcludedPageIds()
119+
public function getExcludedPageIds($storeId = null)
120120
{
121-
$excludedPages = array_values($this->configHelper->getExcludedPages());
121+
$excludedPages = array_values($this->configHelper->getExcludedPages($storeId));
122122
foreach ($excludedPages as &$excludedPage) {
123123
$excludedPage = $excludedPage['attribute'];
124124
}

Helper/Entity/ProductHelper.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,12 @@ public function setSettings(string $indexName, string $indexNameTmp, int $storeI
359359
$this->logger->log('Pushing the same settings to TMP index as well');
360360
}
361361

362-
$this->setFacetsQueryRules($indexName);
362+
$this->setFacetsQueryRules($indexName, $storeId);
363+
$this->algoliaHelper->waitLastTask();
364+
363365
if ($saveToTmpIndicesToo) {
364-
$this->setFacetsQueryRules($indexNameTmp);
366+
$this->setFacetsQueryRules($indexNameTmp, $storeId);
367+
$this->algoliaHelper->waitLastTask();
365368
}
366369

367370
$this->replicaManager->syncReplicasToAlgolia($storeId, $indexSettings);
@@ -1204,17 +1207,16 @@ protected function getAttributesForFaceting($storeId)
12041207

12051208
/**
12061209
* @param $indexName
1210+
* @param $storeId
12071211
* @return void
12081212
* @throws AlgoliaException
12091213
*/
1210-
protected function setFacetsQueryRules($indexName)
1214+
protected function setFacetsQueryRules($indexName, $storeId = null)
12111215
{
1212-
$client = $this->algoliaHelper->getClient();
1213-
12141216
$this->clearFacetsQueryRules($indexName);
12151217

12161218
$rules = [];
1217-
$facets = $this->configHelper->getFacets();
1219+
$facets = $this->configHelper->getFacets($storeId);
12181220
foreach ($facets as $facet) {
12191221
if (!array_key_exists('create_rule', $facet) || $facet['create_rule'] !== '1') {
12201222
continue;
@@ -1245,7 +1247,7 @@ protected function setFacetsQueryRules($indexName)
12451247

12461248
if ($rules) {
12471249
$this->logger->log('Setting facets query rules to "' . $indexName . '" index: ' . json_encode($rules));
1248-
$client->saveRules($indexName, $rules, true);
1250+
$this->algoliaHelper->saveRules($indexName, $rules, true);
12491251
}
12501252
}
12511253

@@ -1260,8 +1262,7 @@ protected function clearFacetsQueryRules($indexName): void
12601262
$hitsPerPage = 100;
12611263
$page = 0;
12621264
do {
1263-
$client = $this->algoliaHelper->getClient();
1264-
$fetchedQueryRules = $client->searchRules($indexName, [
1265+
$fetchedQueryRules = $this->algoliaHelper->searchRules($indexName, [
12651266
'context' => 'magento_filters',
12661267
'page' => $page,
12671268
'hitsPerPage' => $hitsPerPage,
@@ -1273,7 +1274,7 @@ protected function clearFacetsQueryRules($indexName): void
12731274
}
12741275

12751276
foreach ($fetchedQueryRules['hits'] as $hit) {
1276-
$client->deleteRule($indexName, $hit[AlgoliaHelper::ALGOLIA_API_OBJECT_ID], true);
1277+
$this->algoliaHelper->deleteRule($indexName, $hit[AlgoliaHelper::ALGOLIA_API_OBJECT_ID], true);
12771278
}
12781279

12791280
$page++;

Helper/LandingPageHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
parent::__construct($context);
6060
}
6161

62-
public function getLandingPage($pageId)
62+
public function getLandingPage($pageId): LandingPage|null|false
6363
{
6464
if ($pageId !== null && $pageId !== $this->landingPage->getId()) {
6565
$this->landingPage->setStoreId($this->storeManager->getStore()->getId());

Helper/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function isEnable()
3535

3636
public function getStoreName($storeId)
3737
{
38-
if ($storeId === null) {
38+
if ($storeId === null || !isset($this->stores[$storeId])) {
3939
return 'undefined store';
4040
}
4141

0 commit comments

Comments
 (0)