Skip to content

Commit

Permalink
Merge pull request #1643 from algolia/release/3.14.3
Browse files Browse the repository at this point in the history
3.14.3 to main
  • Loading branch information
damcou authored Nov 13, 2024
2 parents 499aa68 + fd6c4cb commit e162a63
Show file tree
Hide file tree
Showing 45 changed files with 2,133 additions and 348 deletions.
3 changes: 2 additions & 1 deletion Block/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
use Algolia\AlgoliaSearch\Helper\LandingPageHelper;
use Algolia\AlgoliaSearch\Model\LandingPage as LandingPageModel;
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
use Algolia\AlgoliaSearch\Service\Product\SortingTransformer;
Expand Down Expand Up @@ -215,7 +216,7 @@ protected function getAddToCartUrl($additional = []): string
return $this->_urlBuilder->getUrl('checkout/cart/add', $routeParams);
}

protected function getCurrentLandingPage(): LandingPage|null|false
protected function getCurrentLandingPage(): LandingPageModel|null|false
{
$landingPageId = $this->getRequest()->getParam('landing_page_id');
if (!$landingPageId) {
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CHANGE LOG

## 3.14.3

### Updates
- Updated PHP client version in the composer file
- Tests: added new integration scenarios including multi-stores ones.

### Bug Fixes
- Fixed landing page typing error
- Improved query method for alternate root categories - Thank you @igorfigueiredogen
- Fixed an error where a missing prefix can throw errors with strong types added to ConfigHelper
- Fixed an error where stale cache data was preventing ranking applied on replica
- Fixed reindexing issue with NeuralSearch
- Tests : Fixed current integration tests

## 3.14.2

### Updates
Expand Down
6 changes: 3 additions & 3 deletions Console/Command/ReplicaSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Service\StoreNameFetcher;
use Magento\Framework\App\State;
use Magento\Framework\App\State as AppState;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -27,12 +27,12 @@ public function __construct(
protected ReplicaManagerInterface $replicaManager,
protected ProductHelper $productHelper,
protected StoreManagerInterface $storeManager,
State $state,
AppState $appState,
StoreNameFetcher $storeNameFetcher,
?string $name = null
)
{
parent::__construct($state, $storeNameFetcher, $name);
parent::__construct($appState, $storeNameFetcher, $name);
}

protected function getReplicaCommandName(): string
Expand Down
35 changes: 34 additions & 1 deletion Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Algolia\AlgoliaSearch\Configuration\SearchConfig;
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
use Algolia\AlgoliaSearch\Model\Search\SearchRulesResponse;
use Algolia\AlgoliaSearch\Response\AbstractResponse;
use Algolia\AlgoliaSearch\Response\BatchIndexingResponse;
use Algolia\AlgoliaSearch\Response\MultiResponse;
Expand Down Expand Up @@ -299,7 +300,7 @@ public function moveIndex(string $fromIndexName, string $toIndexName): void
'destination' => $toIndexName
]
);
self::setLastOperationInfo($fromIndexName, $response);
self::setLastOperationInfo($toIndexName, $response);
}

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

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

if (isset($onlineSettings['mode']) && $onlineSettings['mode'] == 'neuralSearch') {
$removes[] = 'mode';
}

if (isset($settings['attributesToIndex'])) {
$settings['searchableAttributes'] = $settings['attributesToIndex'];
unset($settings['attributesToIndex']);
Expand Down Expand Up @@ -453,6 +458,19 @@ public function saveRule(array $rule, string $indexName, bool $forwardToReplicas
self::setLastOperationInfo($indexName, $res);
}

/**
* @param string $indexName
* @param array $rules
* @param bool $forwardToReplicas
* @return void
*/
public function saveRules(string $indexName, array $rules, bool $forwardToReplicas = false): void
{
$res = $this->client->saveRules($indexName, $rules, $forwardToReplicas);

self::setLastOperationInfo($indexName, $res);
}


/**
* @param string $indexName
Expand Down Expand Up @@ -521,6 +539,21 @@ public function copyQueryRules(string $fromIndexName, string $toIndexName): void
self::setLastOperationInfo($fromIndexName, $response);
}

/**
* @param string $indexName
* @param array|null $searchRulesParams
*
* @return SearchRulesResponse|mixed[]
*
* @throws AlgoliaException
*/
public function searchRules(string $indexName, array$searchRulesParams = null)
{
$this->checkClient(__FUNCTION__);

return $this->client->searchRules($indexName, $searchRulesParams);
}

/**
* @param $methodName
* @return void
Expand Down
6 changes: 3 additions & 3 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function getAutocompleteSections($storeId = null)
}

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

/**
Expand Down Expand Up @@ -1157,7 +1157,7 @@ public function getRawSortingValue(?int $storeId = null): string
* @param int|null $scopeId
* @return void
*/
public function setSorting(array $sorting, ?string $scope = null, ?int $scopeId = null): void
public function setSorting(array $sorting, string $scope = Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ?int $scopeId = null): void
{
$this->configWriter->save(
self::SORTING_INDICES,
Expand Down Expand Up @@ -1242,7 +1242,7 @@ public function getSearchOnlyAPIKey($storeId = null)
*/
public function getIndexPrefix(int $storeId = null): string
{
return $this->configInterface->getValue(self::INDEX_PREFIX, ScopeInterface::SCOPE_STORE, $storeId);
return (string) $this->configInterface->getValue(self::INDEX_PREFIX, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Helper/Entity/CategoryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function getCategoryCollectionQuery($storeId, $categoryIds = null)
{
/** @var \Magento\Store\Model\Store $store */
$store = $this->storeManager->getStore($storeId);
$storeRootCategoryPath = sprintf('%d/%d', $this->getRootCategoryId(), $store->getRootCategoryId());
$storeRootCategoryPath = sprintf('%d/%d/', $this->getRootCategoryId(), $store->getRootCategoryId());

$unserializedCategorysAttrs = $this->getAdditionalAttributes($storeId);
$additionalAttr = array_column($unserializedCategorysAttrs, 'attribute');
Expand Down
6 changes: 3 additions & 3 deletions Helper/Entity/PageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getPages($storeId, array $pageIds = null)
$magentoPages->addFieldToFilter('page_id', ['in' => $pageIds]);
}

$excludedPages = $this->getExcludedPageIds();
$excludedPages = $this->getExcludedPageIds($storeId);
if (count($excludedPages)) {
$magentoPages->addFieldToFilter('identifier', ['nin' => $excludedPages]);
}
Expand Down Expand Up @@ -116,9 +116,9 @@ public function getPages($storeId, array $pageIds = null)
return $pages;
}

public function getExcludedPageIds()
public function getExcludedPageIds($storeId = null)
{
$excludedPages = array_values($this->configHelper->getExcludedPages());
$excludedPages = array_values($this->configHelper->getExcludedPages($storeId));
foreach ($excludedPages as &$excludedPage) {
$excludedPage = $excludedPage['attribute'];
}
Expand Down
21 changes: 11 additions & 10 deletions Helper/Entity/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,12 @@ public function setSettings(string $indexName, string $indexNameTmp, int $storeI
$this->logger->log('Pushing the same settings to TMP index as well');
}

$this->setFacetsQueryRules($indexName);
$this->setFacetsQueryRules($indexName, $storeId);
$this->algoliaHelper->waitLastTask();

if ($saveToTmpIndicesToo) {
$this->setFacetsQueryRules($indexNameTmp);
$this->setFacetsQueryRules($indexNameTmp, $storeId);
$this->algoliaHelper->waitLastTask();
}

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

/**
* @param $indexName
* @param $storeId
* @return void
* @throws AlgoliaException
*/
protected function setFacetsQueryRules($indexName)
protected function setFacetsQueryRules($indexName, $storeId = null)
{
$client = $this->algoliaHelper->getClient();

$this->clearFacetsQueryRules($indexName);

$rules = [];
$facets = $this->configHelper->getFacets();
$facets = $this->configHelper->getFacets($storeId);
foreach ($facets as $facet) {
if (!array_key_exists('create_rule', $facet) || $facet['create_rule'] !== '1') {
continue;
Expand Down Expand Up @@ -1245,7 +1247,7 @@ protected function setFacetsQueryRules($indexName)

if ($rules) {
$this->logger->log('Setting facets query rules to "' . $indexName . '" index: ' . json_encode($rules));
$client->saveRules($indexName, $rules, true);
$this->algoliaHelper->saveRules($indexName, $rules, true);
}
}

Expand All @@ -1260,8 +1262,7 @@ protected function clearFacetsQueryRules($indexName): void
$hitsPerPage = 100;
$page = 0;
do {
$client = $this->algoliaHelper->getClient();
$fetchedQueryRules = $client->searchRules($indexName, [
$fetchedQueryRules = $this->algoliaHelper->searchRules($indexName, [
'context' => 'magento_filters',
'page' => $page,
'hitsPerPage' => $hitsPerPage,
Expand All @@ -1273,7 +1274,7 @@ protected function clearFacetsQueryRules($indexName): void
}

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

$page++;
Expand Down
2 changes: 1 addition & 1 deletion Helper/LandingPageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
parent::__construct($context);
}

public function getLandingPage($pageId)
public function getLandingPage($pageId): LandingPage|null|false
{
if ($pageId !== null && $pageId !== $this->landingPage->getId()) {
$this->landingPage->setStoreId($this->storeManager->getStore()->getId());
Expand Down
2 changes: 1 addition & 1 deletion Helper/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function isEnable()

public function getStoreName($storeId)
{
if ($storeId === null) {
if ($storeId === null || !isset($this->stores[$storeId])) {
return 'undefined store';
}

Expand Down
8 changes: 8 additions & 0 deletions Model/IndicesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,32 @@ public function saveConfigurationToAlgolia(int $storeId, bool $useTmpIndex = fal
}

$this->setCategoriesSettings($storeId);
$this->algoliaHelper->waitLastTask();

/* heck if we want to index CMS pages */
if ($this->configHelper->isPagesIndexEnabled($storeId)) {
$this->setPagesSettings($storeId);
$this->algoliaHelper->waitLastTask();
} else {
$this->logger->log('CMS Page Indexing is not enabled for the store.');
}

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

$this->setAdditionalSectionsSettings($storeId);
$this->algoliaHelper->waitLastTask();

$this->setProductsSettings($storeId, $useTmpIndex);
$this->algoliaHelper->waitLastTask();

$this->setExtraSettings($storeId, $useTmpIndex);
$this->algoliaHelper->waitLastTask();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Algolia Search & Discovery extension for Magento 2
==================================================

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

![PHP](https://img.shields.io/badge/PHP-8.1%2C8.2%2C8.3-blue)
Expand Down
8 changes: 5 additions & 3 deletions Service/Product/ReplicaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ protected function clearAlgoliaReplicaSettingCache($primaryIndexName = null): vo
* relevant to the Magento integration
*
* @param string $primaryIndexName
* @param bool $refreshCache
* @return string[] Array of replica index names
* @throws LocalizedException
* @throws NoSuchEntityException
*/
protected function getMagentoReplicaConfigurationFromAlgolia(string $primaryIndexName): array
protected function getMagentoReplicaConfigurationFromAlgolia(string $primaryIndexName, bool $refreshCache = false): array
{
$algoliaReplicas = $this->getReplicaConfigurationFromAlgolia($primaryIndexName);
$algoliaReplicas = $this->getReplicaConfigurationFromAlgolia($primaryIndexName, $refreshCache);
$magentoReplicas = $this->getMagentoReplicaSettings($primaryIndexName, $algoliaReplicas);
return array_values(array_intersect($magentoReplicas, $algoliaReplicas));
}
Expand Down Expand Up @@ -241,7 +243,7 @@ protected function setReplicasOnPrimaryIndex(int $storeId): array
$indexName = $this->indexNameFetcher->getProductIndexName($storeId);
$sortingIndices = $this->sortingTransformer->getSortingIndices($storeId);
$newMagentoReplicasSetting = $this->sortingTransformer->transformSortingIndicesToReplicaSetting($sortingIndices);
$oldMagentoReplicasSetting = $this->getMagentoReplicaConfigurationFromAlgolia($indexName);
$oldMagentoReplicasSetting = $this->getMagentoReplicaConfigurationFromAlgolia($indexName, true);
$nonMagentoReplicasSetting = $this->getNonMagentoReplicaConfigurationFromAlgolia($indexName);
$oldMagentoReplicaIndices = $this->getBareIndexNamesFromReplicaSetting($oldMagentoReplicasSetting);
$newMagentoReplicaIndices = $this->getBareIndexNamesFromReplicaSetting($newMagentoReplicasSetting);
Expand Down
4 changes: 2 additions & 2 deletions Setup/Patch/Schema/ConfigPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ConfigPatch implements SchemaPatchInterface
],
],

'algoliasearch_instant/instant/facets' => [
'algoliasearch_instant/instant_facets/facets' => [
[
'attribute' => 'price',
'type' => 'slider',
Expand All @@ -135,7 +135,7 @@ class ConfigPatch implements SchemaPatchInterface
'create_rule' => '2',
],
],
'algoliasearch_instant/instant/sorts' => [
'algoliasearch_instant/instant_sorts/sorts' => [
[
'attribute' => 'price',
'sort' => 'asc',
Expand Down
15 changes: 0 additions & 15 deletions Test/Integration/AssertValues/Magento23.php

This file was deleted.

8 changes: 8 additions & 0 deletions Test/Integration/AssertValues/Magento246CE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;

class Magento246CE extends Magento24CE
{

}
8 changes: 8 additions & 0 deletions Test/Integration/AssertValues/Magento246EE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;

class Magento246EE extends Magento24EE
{

}
8 changes: 8 additions & 0 deletions Test/Integration/AssertValues/Magento247CE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues;

class Magento247CE extends Magento24CE
{

}
Loading

0 comments on commit e162a63

Please sign in to comment.