From d0e25ed3913ba926c1be67d6f8749b52f38f1ad8 Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Thu, 6 Nov 2025 16:39:30 +0100 Subject: [PATCH 1/7] MAGE-1328: add new configurations --- Helper/Configuration/AutocompleteHelper.php | 39 +++++++++++++++++++++ Model/Source/Suggestions.php | 31 ++++++++++++++++ etc/adminhtml/system.xml | 29 ++++++++++++++- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 Model/Source/Suggestions.php diff --git a/Helper/Configuration/AutocompleteHelper.php b/Helper/Configuration/AutocompleteHelper.php index 0b014440b..25baa99a7 100644 --- a/Helper/Configuration/AutocompleteHelper.php +++ b/Helper/Configuration/AutocompleteHelper.php @@ -3,6 +3,7 @@ namespace Algolia\AlgoliaSearch\Helper\Configuration; use Algolia\AlgoliaSearch\Service\Serializer; +use Algolia\AlgoliaSearch\Model\Source\Suggestions; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; @@ -13,9 +14,12 @@ class AutocompleteHelper public const ADDITIONAL_SECTIONS = 'algoliasearch_autocomplete/autocomplete/sections'; public const NB_OF_PRODUCTS_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_products_suggestions'; public const NB_OF_CATEGORIES_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_categories_suggestions'; + + public const SUGGESTIONS_MODE = 'algoliasearch_autocomplete/autocomplete/suggestions_mode'; public const NB_OF_QUERIES_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_queries_suggestions'; public const MIN_QUERY_POPULARITY = 'algoliasearch_autocomplete/autocomplete/min_popularity'; public const MIN_QUERY_NUMBER_OF_RESULTS = 'algoliasearch_autocomplete/autocomplete/min_number_of_results'; + public const SUGGESTIONS_INDEX_NAME = 'algoliasearch_autocomplete/autocomplete/suggestions_index_name'; public const EXCLUDED_PAGES = 'algoliasearch_autocomplete/autocomplete/excluded_pages'; public const RENDER_TEMPLATE_DIRECTIVES = 'algoliasearch_autocomplete/autocomplete/render_template_directives'; @@ -79,6 +83,32 @@ public function getNumberOfCategoriesSuggestions(?int $storeId = null): int ); } + public function areSuggestionsEnabled(?int $storeId = null): bool + { + return $this->getSuggestionsMode($storeId) > 0; + } + + public function areMagentoSearchQueriesEnabled(?int $storeId = null): bool + { + return $this->getSuggestionsMode($storeId) === Suggestions::SUGGESTIONS_MAGENTO + && $this->getNumberOfQueriesSuggestions($storeId) > 0; + } + + public function areAlgoliaQuerySuggestionsEnabled(?int $storeId = null): bool + { + return $this->getSuggestionsMode($storeId) === Suggestions::SUGGESTIONS_ALGOLIA + && $this->getSuggestionsIndexName($storeId) !== ''; + } + + public function getSuggestionsMode(?int $storeId = null): int + { + return (int) $this->configInterface->getValue( + self::SUGGESTIONS_MODE, + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + public function getNumberOfQueriesSuggestions(?int $storeId = null): int { return (int) $this->configInterface->getValue( @@ -108,6 +138,15 @@ public function getMinQueryNumberOfResults(?int $storeId = null): int ); } + public function getSuggestionsIndexName(?int $storeId = null): string + { + return $this->configInterface->getValue( + self::SUGGESTIONS_INDEX_NAME, + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + /** * Retrieve CMS pages to be excluded from the Autocomplete search * Also impacts what pages are indexed diff --git a/Model/Source/Suggestions.php b/Model/Source/Suggestions.php new file mode 100644 index 000000000..52b2f2163 --- /dev/null +++ b/Model/Source/Suggestions.php @@ -0,0 +1,31 @@ + self::SUGGESTIONS_DISABLED, + 'label' => __('No'), + ], + [ + 'value' => self::SUGGESTIONS_MAGENTO, + 'label' => __('Use Magento Search Queries (deprecated)'), + ], + [ + 'value' => self::SUGGESTIONS_ALGOLIA, + 'label' => __('Use Algolia Query Suggestions'), + ], + ]; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f5412d1a0..50b21b5bc 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -166,7 +166,19 @@ 1 - + + + Algolia\AlgoliaSearch\Model\Source\Suggestions + + search_query table) or the Algolia Suggestions from your Algolia dashboard. + ]]> + + + 1 + + + validate-digits @@ -177,6 +189,7 @@ 1 + 1 @@ -189,6 +202,7 @@ 1 + 1 @@ -201,6 +215,19 @@ 1 + 1 + + + + + + + + + 1 + 2 From a1d293d88707f2a4ffc25bd16e76aeb926e8cf27 Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Thu, 6 Nov 2025 17:09:19 +0100 Subject: [PATCH 2/7] MAGE-1328: add configuration to frontend block and add defaults --- Block/Configuration.php | 10 ++++++++++ Helper/Configuration/AutocompleteHelper.php | 17 ++++++++++++++--- etc/adminhtml/system.xml | 21 +++++++++++++++++---- etc/config.xml | 3 +++ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Block/Configuration.php b/Block/Configuration.php index 8d8be8b1d..3ef82fb85 100755 --- a/Block/Configuration.php +++ b/Block/Configuration.php @@ -371,7 +371,17 @@ protected function getAutocompleteConfiguration(): array 'sections' => $config->getAdditionalSections(), 'nbOfProductsSuggestions' => $config->getNumberOfProductsSuggestions(), 'nbOfCategoriesSuggestions' => $config->getNumberOfCategoriesSuggestions(), + // SUGGESTIONS - START + 'areSuggestionsEnabled' => $config->areSuggestionsEnabled(), + 'suggestionsMode' => $config->getSuggestionsMode(), + // Magento + 'showMagentoSuggestions' => $config->showMagentoSuggestions(), 'nbOfQueriesSuggestions' => $config->getNumberOfQueriesSuggestions(), + // Algolia + 'showAlgoliaSuggestions' => $config->showAlgoliaSuggestions(), + 'suggestionsIndexName' => $config->getSuggestionsIndexName(), + 'nbOfAlgoliaSuggestions' => $config->getNumberOfAlgoliaSuggestions(), + // SUGGESTIONS - END 'isDebugEnabled' => $config->isDebugEnabled(), 'isNavigatorEnabled' => $config->isKeyboardNavigationEnabled(), 'debounceMilliseconds' => $config->getDebounceMilliseconds(), diff --git a/Helper/Configuration/AutocompleteHelper.php b/Helper/Configuration/AutocompleteHelper.php index 25baa99a7..a313b4b92 100644 --- a/Helper/Configuration/AutocompleteHelper.php +++ b/Helper/Configuration/AutocompleteHelper.php @@ -20,6 +20,7 @@ class AutocompleteHelper public const MIN_QUERY_POPULARITY = 'algoliasearch_autocomplete/autocomplete/min_popularity'; public const MIN_QUERY_NUMBER_OF_RESULTS = 'algoliasearch_autocomplete/autocomplete/min_number_of_results'; public const SUGGESTIONS_INDEX_NAME = 'algoliasearch_autocomplete/autocomplete/suggestions_index_name'; + public const NB_OF_ALGOLIA_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_algolia_suggestions'; public const EXCLUDED_PAGES = 'algoliasearch_autocomplete/autocomplete/excluded_pages'; public const RENDER_TEMPLATE_DIRECTIVES = 'algoliasearch_autocomplete/autocomplete/render_template_directives'; @@ -88,16 +89,17 @@ public function areSuggestionsEnabled(?int $storeId = null): bool return $this->getSuggestionsMode($storeId) > 0; } - public function areMagentoSearchQueriesEnabled(?int $storeId = null): bool + public function showMagentoSuggestions(?int $storeId = null): bool { return $this->getSuggestionsMode($storeId) === Suggestions::SUGGESTIONS_MAGENTO && $this->getNumberOfQueriesSuggestions($storeId) > 0; } - public function areAlgoliaQuerySuggestionsEnabled(?int $storeId = null): bool + public function showAlgoliaSuggestions(?int $storeId = null): bool { return $this->getSuggestionsMode($storeId) === Suggestions::SUGGESTIONS_ALGOLIA - && $this->getSuggestionsIndexName($storeId) !== ''; + && $this->getSuggestionsIndexName($storeId) !== '' + && $this->getNumberOfAlgoliaSuggestions($storeId) > 0; } public function getSuggestionsMode(?int $storeId = null): int @@ -147,6 +149,15 @@ public function getSuggestionsIndexName(?int $storeId = null): string ); } + public function getNumberOfAlgoliaSuggestions(?int $storeId = null): int + { + return (int) $this->configInterface->getValue( + self::NB_OF_ALGOLIA_SUGGESTIONS, + ScopeInterface::SCOPE_STORE, + $storeId + ); + } + /** * Retrieve CMS pages to be excluded from the Autocomplete search * Also impacts what pages are indexed diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 50b21b5bc..0bfc79787 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -189,7 +189,7 @@ 1 - 1 + 1 @@ -202,7 +202,7 @@ 1 - 1 + 1 @@ -215,7 +215,7 @@ 1 - 1 + 1 @@ -227,7 +227,20 @@ 1 - 2 + 2 + + + + validate-digits + + + + + + 1 + 2 diff --git a/etc/config.xml b/etc/config.xml index e291ce3d1..11c3105ab 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -27,9 +27,12 @@ .algolia-search-input 6 2 + 0 0 1000 2 + query_suggestions_test + 2 1 From 9ab19a11c618d78a5158c304aaee3e6a4e414d14 Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Fri, 7 Nov 2025 14:25:35 +0100 Subject: [PATCH 3/7] MAGE-1328: add data patch to activate Magento Suggestions in case it was activated before --- .../Data/MigrateSuggestionsConfigPatch.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Setup/Patch/Data/MigrateSuggestionsConfigPatch.php diff --git a/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php b/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php new file mode 100644 index 000000000..050b3d2c0 --- /dev/null +++ b/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php @@ -0,0 +1,79 @@ +moduleDataSetup->getConnection()->startSetup(); + + $this->moveIndexingSettings(); + + $this->moduleDataSetup->getConnection()->endSetup(); + + return $this; + } + + /** + * Migrate legacy configurations + * @return void + */ + protected function moveIndexingSettings(): void + { + $connection = $this->moduleDataSetup->getConnection(); + $configDataTable = $this->moduleDataSetup->getTable('core_config_data'); + + // Get current number of configured Magento suggestions + $whereConfigPathFrom = $connection->quoteInto('path = ?', AutocompleteHelper::NB_OF_QUERIES_SUGGESTIONS); + $select = $connection->select() + ->from($configDataTable) + ->where($whereConfigPathFrom); + $existingValues = $connection->fetchAll($select); + + foreach ($existingValues as $item) { + // If number of suggestions used to be superior to zero, this means that the feature was activated + // So we automatically set the suggestion mode to "Magento" + if ((int) $item['value'] > 0) { + $connection->insertOnDuplicate( + $configDataTable, + [ + 'scope' => $item['scope'], + 'scope_id' => $item['scope_id'], + 'path' => AutocompleteHelper::SUGGESTIONS_MODE, + 'value' => Suggestions::SUGGESTIONS_MAGENTO + ] + ); + } + } + } + + /** + * @inheritDoc + */ + public static function getDependencies(): array + { + return []; + } + + /** + * @inheritDoc + */ + public function getAliases(): array + { + return []; + } +} From fa35c473c5ad3b836d4bbd10bcb45270ca42b65f Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Fri, 7 Nov 2025 14:33:24 +0100 Subject: [PATCH 4/7] MAGE-1328: add condition for the suggestion indexing to depend on the suggestions mode --- Service/Suggestion/BatchQueueProcessor.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Service/Suggestion/BatchQueueProcessor.php b/Service/Suggestion/BatchQueueProcessor.php index 132190ca7..a31ff1fc4 100644 --- a/Service/Suggestion/BatchQueueProcessor.php +++ b/Service/Suggestion/BatchQueueProcessor.php @@ -3,8 +3,10 @@ namespace Algolia\AlgoliaSearch\Service\Suggestion; use Algolia\AlgoliaSearch\Api\Processor\BatchQueueProcessorInterface; +use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper; use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\Queue; +use Algolia\AlgoliaSearch\Model\Source\Suggestions; use Algolia\AlgoliaSearch\Service\AlgoliaCredentialsManager; use Algolia\AlgoliaSearch\Service\Suggestion\IndexBuilder as SuggestionIndexBuilder; @@ -12,13 +14,15 @@ class BatchQueueProcessor implements BatchQueueProcessorInterface { public function __construct( protected Data $dataHelper, + protected AutocompleteHelper $autocompleteHelper, protected Queue $queue, protected AlgoliaCredentialsManager $algoliaCredentialsManager ){} public function processBatch(int $storeId, ?array $entityIds = null): void { - if ($this->dataHelper->isIndexingEnabled($storeId) === false) { + if ($this->dataHelper->isIndexingEnabled($storeId) === false + || $this->autocompleteHelper->getSuggestionsMode($storeId) !== Suggestions::SUGGESTIONS_MAGENTO) { return; } From f54561676c08857341ead73d2e60203fb4426d4e Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Fri, 7 Nov 2025 14:39:46 +0100 Subject: [PATCH 5/7] MAGE-1328: add documentation link to the configuration --- etc/adminhtml/system.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 0bfc79787..34a155764 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -222,7 +222,8 @@ + For more information, check the Algolia official documentation ]]> From 6b36823caf296c7e3115242f3f6ea490fb241bba Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 12 Nov 2025 10:07:06 +0100 Subject: [PATCH 6/7] MAGE-1328: remove indexing control --- Service/Suggestion/BatchQueueProcessor.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Service/Suggestion/BatchQueueProcessor.php b/Service/Suggestion/BatchQueueProcessor.php index a31ff1fc4..132190ca7 100644 --- a/Service/Suggestion/BatchQueueProcessor.php +++ b/Service/Suggestion/BatchQueueProcessor.php @@ -3,10 +3,8 @@ namespace Algolia\AlgoliaSearch\Service\Suggestion; use Algolia\AlgoliaSearch\Api\Processor\BatchQueueProcessorInterface; -use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper; use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\Queue; -use Algolia\AlgoliaSearch\Model\Source\Suggestions; use Algolia\AlgoliaSearch\Service\AlgoliaCredentialsManager; use Algolia\AlgoliaSearch\Service\Suggestion\IndexBuilder as SuggestionIndexBuilder; @@ -14,15 +12,13 @@ class BatchQueueProcessor implements BatchQueueProcessorInterface { public function __construct( protected Data $dataHelper, - protected AutocompleteHelper $autocompleteHelper, protected Queue $queue, protected AlgoliaCredentialsManager $algoliaCredentialsManager ){} public function processBatch(int $storeId, ?array $entityIds = null): void { - if ($this->dataHelper->isIndexingEnabled($storeId) === false - || $this->autocompleteHelper->getSuggestionsMode($storeId) !== Suggestions::SUGGESTIONS_MAGENTO) { + if ($this->dataHelper->isIndexingEnabled($storeId) === false) { return; } From 5b67ca19401b194082685984b34848cbd752c49a Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 12 Nov 2025 10:07:56 +0100 Subject: [PATCH 7/7] Update Setup/Patch/Data/MigrateSuggestionsConfigPatch.php Co-authored-by: Eric Wright --- Setup/Patch/Data/MigrateSuggestionsConfigPatch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php b/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php index 050b3d2c0..bcde6f6ab 100644 --- a/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php +++ b/Setup/Patch/Data/MigrateSuggestionsConfigPatch.php @@ -41,7 +41,7 @@ protected function moveIndexingSettings(): void $whereConfigPathFrom = $connection->quoteInto('path = ?', AutocompleteHelper::NB_OF_QUERIES_SUGGESTIONS); $select = $connection->select() ->from($configDataTable) - ->where($whereConfigPathFrom); + ->where('path = ?', AutocompleteHelper::NB_OF_QUERIES_SUGGESTIONS); $existingValues = $connection->fetchAll($select); foreach ($existingValues as $item) {