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

Model/IndicesConfigurator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,32 @@ public function saveConfigurationToAlgolia(int $storeId, bool $useTmpIndex = fal
104104
}
105105

106106
$this->setCategoriesSettings($storeId);
107+
$this->algoliaHelper->waitLastTask();
108+
107109
/* heck if we want to index CMS pages */
108110
if ($this->configHelper->isPagesIndexEnabled($storeId)) {
109111
$this->setPagesSettings($storeId);
112+
$this->algoliaHelper->waitLastTask();
110113
} else {
111114
$this->logger->log('CMS Page Indexing is not enabled for the store.');
112115
}
113116

114117
//Check if we want to index Query Suggestions
115118
if ($this->configHelper->isQuerySuggestionsIndexEnabled($storeId)) {
116119
$this->setQuerySuggestionsSettings($storeId);
120+
$this->algoliaHelper->waitLastTask();
117121
} else {
118122
$this->logger->log('Query Suggestions Indexing is not enabled for the store.');
119123
}
120124

121125
$this->setAdditionalSectionsSettings($storeId);
126+
$this->algoliaHelper->waitLastTask();
127+
122128
$this->setProductsSettings($storeId, $useTmpIndex);
129+
$this->algoliaHelper->waitLastTask();
123130

124131
$this->setExtraSettings($storeId, $useTmpIndex);
132+
$this->algoliaHelper->waitLastTask();
125133
}
126134

127135
/**

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Algolia Search & Discovery extension for Magento 2
22
==================================================
33

4-
![Latest version](https://img.shields.io/badge/latest-3.14.2-green)
4+
![Latest version](https://img.shields.io/badge/latest-3.14.3-green)
55
![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange)
66

77
![PHP](https://img.shields.io/badge/PHP-8.1%2C8.2%2C8.3-blue)

Service/Product/ReplicaManager.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ protected function clearAlgoliaReplicaSettingCache($primaryIndexName = null): vo
133133
* relevant to the Magento integration
134134
*
135135
* @param string $primaryIndexName
136+
* @param bool $refreshCache
136137
* @return string[] Array of replica index names
137138
* @throws LocalizedException
139+
* @throws NoSuchEntityException
138140
*/
139-
protected function getMagentoReplicaConfigurationFromAlgolia(string $primaryIndexName): array
141+
protected function getMagentoReplicaConfigurationFromAlgolia(string $primaryIndexName, bool $refreshCache = false): array
140142
{
141-
$algoliaReplicas = $this->getReplicaConfigurationFromAlgolia($primaryIndexName);
143+
$algoliaReplicas = $this->getReplicaConfigurationFromAlgolia($primaryIndexName, $refreshCache);
142144
$magentoReplicas = $this->getMagentoReplicaSettings($primaryIndexName, $algoliaReplicas);
143145
return array_values(array_intersect($magentoReplicas, $algoliaReplicas));
144146
}
@@ -241,7 +243,7 @@ protected function setReplicasOnPrimaryIndex(int $storeId): array
241243
$indexName = $this->indexNameFetcher->getProductIndexName($storeId);
242244
$sortingIndices = $this->sortingTransformer->getSortingIndices($storeId);
243245
$newMagentoReplicasSetting = $this->sortingTransformer->transformSortingIndicesToReplicaSetting($sortingIndices);
244-
$oldMagentoReplicasSetting = $this->getMagentoReplicaConfigurationFromAlgolia($indexName);
246+
$oldMagentoReplicasSetting = $this->getMagentoReplicaConfigurationFromAlgolia($indexName, true);
245247
$nonMagentoReplicasSetting = $this->getNonMagentoReplicaConfigurationFromAlgolia($indexName);
246248
$oldMagentoReplicaIndices = $this->getBareIndexNamesFromReplicaSetting($oldMagentoReplicasSetting);
247249
$newMagentoReplicaIndices = $this->getBareIndexNamesFromReplicaSetting($newMagentoReplicasSetting);

Setup/Patch/Schema/ConfigPatch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class ConfigPatch implements SchemaPatchInterface
112112
],
113113
],
114114

115-
'algoliasearch_instant/instant/facets' => [
115+
'algoliasearch_instant/instant_facets/facets' => [
116116
[
117117
'attribute' => 'price',
118118
'type' => 'slider',
@@ -135,7 +135,7 @@ class ConfigPatch implements SchemaPatchInterface
135135
'create_rule' => '2',
136136
],
137137
],
138-
'algoliasearch_instant/instant/sorts' => [
138+
'algoliasearch_instant/instant_sorts/sorts' => [
139139
[
140140
'attribute' => 'price',
141141
'sort' => 'asc',

Test/Integration/AssertValues/Magento23.php

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;
4+
5+
class Magento246CE extends Magento24CE
6+
{
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;
4+
5+
class Magento246EE extends Magento24EE
6+
{
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;
4+
5+
class Magento247CE extends Magento24CE
6+
{
7+
8+
}

0 commit comments

Comments
 (0)