|
4 | 4 |
|
5 | 5 | use Algolia\AlgoliaSearch\Helper\ConfigHelper;
|
6 | 6 | use Algolia\AlgoliaSearch\Helper\InsightsHelper;
|
| 7 | +use Algolia\AlgoliaSearch\Model\Source\AutocompleteRedirectMode; |
| 8 | +use Algolia\AlgoliaSearch\Model\Source\InstantSearchRedirectOptions; |
7 | 9 | use Magento\Framework\App\Request\Http;
|
8 | 10 | use Magento\Framework\Data\CollectionDataSourceInterface;
|
9 | 11 | use Magento\Framework\DataObject;
|
@@ -185,33 +187,8 @@ public function getConfiguration()
|
185 | 187 |
|
186 | 188 | $attributesToFilter = $config->getAttributesToFilter($customerGroupId);
|
187 | 189 | $algoliaJsConfig = [
|
188 |
| - 'instant' => [ |
189 |
| - 'enabled' => $config->isInstantEnabled(), |
190 |
| - 'selector' => $config->getInstantSelector(), |
191 |
| - 'isAddToCartEnabled' => $config->isAddToCartEnable(), |
192 |
| - 'addToCartParams' => $addToCartParams, |
193 |
| - 'infiniteScrollEnabled' => $config->isInfiniteScrollEnabled(), |
194 |
| - 'urlTrackedParameters' => $this->getUrlTrackedParameters(), |
195 |
| - 'isSearchBoxEnabled' => $config->isInstantSearchBoxEnabled(), |
196 |
| - 'isVisualMerchEnabled' => $config->isVisualMerchEnabled(), |
197 |
| - 'categorySeparator' => $config->getCategorySeparator(), |
198 |
| - 'categoryPageIdAttribute' => $config->getCategoryPageIdAttributeName(), |
199 |
| - 'isCategoryNavigationEnabled' => self::IS_CATEGORY_NAVIGATION_ENABLED, |
200 |
| - 'hidePagination' => $config->hidePaginationInInstantSearchPage(), |
201 |
| - 'isDynamicFacetsEnabled' => $config->isDynamicFacetsEnabled() |
202 |
| - ], |
203 |
| - 'autocomplete' => [ |
204 |
| - 'enabled' => $config->isAutoCompleteEnabled(), |
205 |
| - 'selector' => $config->getAutocompleteSelector(), |
206 |
| - 'sections' => $config->getAutocompleteSections(), |
207 |
| - 'nbOfProductsSuggestions' => $config->getNumberOfProductsSuggestions(), |
208 |
| - 'nbOfCategoriesSuggestions' => $config->getNumberOfCategoriesSuggestions(), |
209 |
| - 'nbOfQueriesSuggestions' => $config->getNumberOfQueriesSuggestions(), |
210 |
| - 'isDebugEnabled' => $config->isAutocompleteDebugEnabled(), |
211 |
| - 'isNavigatorEnabled' => $config->isAutocompleteNavigatorEnabled(), |
212 |
| - 'debounceMilliseconds' => $config->getAutocompleteDebounceMilliseconds(), |
213 |
| - 'minimumCharacters' => $config->getAutocompleteMinimumCharacterLength() |
214 |
| - ], |
| 190 | + 'instant' => $this->getInstantSearchConfig($addToCartParams), |
| 191 | + 'autocomplete' => $this->getAutocompleteConfiguration(), |
215 | 192 | 'landingPage' => [
|
216 | 193 | 'query' => $this->getLandingPageQuery(),
|
217 | 194 | 'configuration' => $this->getLandingPageConfiguration(),
|
@@ -385,6 +362,59 @@ public function getConfiguration()
|
385 | 362 | return $transport->getData();
|
386 | 363 | }
|
387 | 364 |
|
| 365 | + protected function getAutocompleteConfiguration(): array |
| 366 | + { |
| 367 | + $config = $this->autocompleteConfig; |
| 368 | + return [ |
| 369 | + 'enabled' => $config->isEnabled(), |
| 370 | + 'selector' => $config->getDomSelector(), |
| 371 | + 'sections' => $config->getAdditionalSections(), |
| 372 | + 'nbOfProductsSuggestions' => $config->getNumberOfProductsSuggestions(), |
| 373 | + 'nbOfCategoriesSuggestions' => $config->getNumberOfCategoriesSuggestions(), |
| 374 | + 'nbOfQueriesSuggestions' => $config->getNumberOfQueriesSuggestions(), |
| 375 | + 'isDebugEnabled' => $config->isDebugEnabled(), |
| 376 | + 'isNavigatorEnabled' => $config->isKeyboardNavigationEnabled(), |
| 377 | + 'debounceMilliseconds' => $config->getDebounceMilliseconds(), |
| 378 | + 'minimumCharacters' => $config->getMinimumCharacterLength(), |
| 379 | + 'redirects' => [ |
| 380 | + 'enabled' => $config->isRedirectEnabled(), |
| 381 | + 'showSelectableRedirect' => $config->getRedirectMode() !== AutocompleteRedirectMode::SUBMIT_ONLY, |
| 382 | + 'showHitsWithRedirect' => $config->getRedirectMode() !== AutocompleteRedirectMode::SELECTABLE_REDIRECT, |
| 383 | + 'openInNewWindow' => $config->isRedirectInNewWindowEnabled() |
| 384 | + ] |
| 385 | + ]; |
| 386 | + } |
| 387 | + |
| 388 | + protected function getInstantSearchConfig(array $addToCartParams): array |
| 389 | + { |
| 390 | + $config = $this->instantSearchConfig; |
| 391 | + $redirectOptions = $config->getInstantRedirectOptions(); |
| 392 | + $mainConfig = $this->config; |
| 393 | + |
| 394 | + return [ |
| 395 | + 'enabled' => $config->isEnabled(), |
| 396 | + 'selector' => $config->getDomSelector(), |
| 397 | + 'isAddToCartEnabled' => $config->isAddToCartEnabled(), |
| 398 | + 'addToCartParams' => $addToCartParams, |
| 399 | + 'infiniteScrollEnabled' => $config->isInfiniteScrollEnabled(), |
| 400 | + 'urlTrackedParameters' => $this->getUrlTrackedParameters(), |
| 401 | + 'isSearchBoxEnabled' => $config->isSearchBoxEnabled(), |
| 402 | + 'isVisualMerchEnabled' => $mainConfig->isVisualMerchEnabled(), |
| 403 | + 'categorySeparator' => $mainConfig->getCategorySeparator(), |
| 404 | + 'categoryPageIdAttribute' => $mainConfig->getCategoryPageIdAttributeName(), |
| 405 | + 'isCategoryNavigationEnabled' => self::IS_CATEGORY_NAVIGATION_ENABLED, |
| 406 | + 'hidePagination' => $config->shouldHidePagination(), |
| 407 | + 'isDynamicFacetsEnabled' => $config->isDynamicFacetsEnabled(), |
| 408 | + 'redirects' => [ |
| 409 | + 'enabled' => $config->isInstantRedirectEnabled(), |
| 410 | + 'onPageLoad' => in_array(InstantSearchRedirectOptions::REDIRECT_ON_PAGE_LOAD, $redirectOptions), |
| 411 | + 'onSearchAsYouType' => in_array(InstantSearchRedirectOptions::REDIRECT_ON_SEARCH_AS_YOU_TYPE, $redirectOptions), |
| 412 | + 'showSelectableRedirect' => in_array(InstantSearchRedirectOptions::SELECTABLE_REDIRECT, $redirectOptions), |
| 413 | + 'openInNewWindow' => in_array(InstantSearchRedirectOptions::OPEN_IN_NEW_WINDOW, $redirectOptions) |
| 414 | + ] |
| 415 | + ]; |
| 416 | + } |
| 417 | + |
388 | 418 | protected function areCategoriesInFacets($facets)
|
389 | 419 | {
|
390 | 420 | return in_array('categories', array_column($facets, 'attribute'));
|
|
0 commit comments