33namespace Algolia \AlgoliaSearch \Helper \Configuration ;
44
55use Algolia \AlgoliaSearch \Service \Serializer ;
6+ use Algolia \AlgoliaSearch \Model \Source \Suggestions ;
67use Magento \Framework \App \Config \ScopeConfigInterface ;
78use Magento \Store \Model \ScopeInterface ;
89
@@ -13,9 +14,13 @@ class AutocompleteHelper
1314 public const ADDITIONAL_SECTIONS = 'algoliasearch_autocomplete/autocomplete/sections ' ;
1415 public const NB_OF_PRODUCTS_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_products_suggestions ' ;
1516 public const NB_OF_CATEGORIES_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_categories_suggestions ' ;
17+
18+ public const SUGGESTIONS_MODE = 'algoliasearch_autocomplete/autocomplete/suggestions_mode ' ;
1619 public const NB_OF_QUERIES_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_queries_suggestions ' ;
1720 public const MIN_QUERY_POPULARITY = 'algoliasearch_autocomplete/autocomplete/min_popularity ' ;
1821 public const MIN_QUERY_NUMBER_OF_RESULTS = 'algoliasearch_autocomplete/autocomplete/min_number_of_results ' ;
22+ public const SUGGESTIONS_INDEX_NAME = 'algoliasearch_autocomplete/autocomplete/suggestions_index_name ' ;
23+ public const NB_OF_ALGOLIA_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_algolia_suggestions ' ;
1924
2025 public const EXCLUDED_PAGES = 'algoliasearch_autocomplete/autocomplete/excluded_pages ' ;
2126 public const RENDER_TEMPLATE_DIRECTIVES = 'algoliasearch_autocomplete/autocomplete/render_template_directives ' ;
@@ -79,6 +84,33 @@ public function getNumberOfCategoriesSuggestions(?int $storeId = null): int
7984 );
8085 }
8186
87+ public function areSuggestionsEnabled (?int $ storeId = null ): bool
88+ {
89+ return $ this ->getSuggestionsMode ($ storeId ) > 0 ;
90+ }
91+
92+ public function showMagentoSuggestions (?int $ storeId = null ): bool
93+ {
94+ return $ this ->getSuggestionsMode ($ storeId ) === Suggestions::SUGGESTIONS_MAGENTO
95+ && $ this ->getNumberOfQueriesSuggestions ($ storeId ) > 0 ;
96+ }
97+
98+ public function showAlgoliaSuggestions (?int $ storeId = null ): bool
99+ {
100+ return $ this ->getSuggestionsMode ($ storeId ) === Suggestions::SUGGESTIONS_ALGOLIA
101+ && $ this ->getSuggestionsIndexName ($ storeId ) !== ''
102+ && $ this ->getNumberOfAlgoliaSuggestions ($ storeId ) > 0 ;
103+ }
104+
105+ public function getSuggestionsMode (?int $ storeId = null ): int
106+ {
107+ return (int ) $ this ->configInterface ->getValue (
108+ self ::SUGGESTIONS_MODE ,
109+ ScopeInterface::SCOPE_STORE ,
110+ $ storeId
111+ );
112+ }
113+
82114 public function getNumberOfQueriesSuggestions (?int $ storeId = null ): int
83115 {
84116 return (int ) $ this ->configInterface ->getValue (
@@ -108,6 +140,24 @@ public function getMinQueryNumberOfResults(?int $storeId = null): int
108140 );
109141 }
110142
143+ public function getSuggestionsIndexName (?int $ storeId = null ): string
144+ {
145+ return $ this ->configInterface ->getValue (
146+ self ::SUGGESTIONS_INDEX_NAME ,
147+ ScopeInterface::SCOPE_STORE ,
148+ $ storeId
149+ );
150+ }
151+
152+ public function getNumberOfAlgoliaSuggestions (?int $ storeId = null ): int
153+ {
154+ return (int ) $ this ->configInterface ->getValue (
155+ self ::NB_OF_ALGOLIA_SUGGESTIONS ,
156+ ScopeInterface::SCOPE_STORE ,
157+ $ storeId
158+ );
159+ }
160+
111161 /**
112162 * Retrieve CMS pages to be excluded from the Autocomplete search
113163 * Also impacts what pages are indexed
0 commit comments