Skip to content

Commit 853e9eb

Browse files
committed
MAGE-986 Refactor config to utilize InstantSearch helper
1 parent 08fc100 commit 853e9eb

File tree

4 files changed

+532
-318
lines changed

4 files changed

+532
-318
lines changed

Block/Configuration.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,28 +187,7 @@ public function getConfiguration()
187187

188188
$attributesToFilter = $config->getAttributesToFilter($customerGroupId);
189189
$algoliaJsConfig = [
190-
'instant' => [
191-
'enabled' => $config->isInstantEnabled(),
192-
'selector' => $config->getInstantSelector(),
193-
'isAddToCartEnabled' => $config->isAddToCartEnable(),
194-
'addToCartParams' => $addToCartParams,
195-
'infiniteScrollEnabled' => $config->isInfiniteScrollEnabled(),
196-
'urlTrackedParameters' => $this->getUrlTrackedParameters(),
197-
'isSearchBoxEnabled' => $config->isInstantSearchBoxEnabled(),
198-
'isVisualMerchEnabled' => $config->isVisualMerchEnabled(),
199-
'categorySeparator' => $config->getCategorySeparator(),
200-
'categoryPageIdAttribute' => $config->getCategoryPageIdAttributeName(),
201-
'isCategoryNavigationEnabled' => self::IS_CATEGORY_NAVIGATION_ENABLED,
202-
'hidePagination' => $config->hidePaginationInInstantSearchPage(),
203-
'isDynamicFacetsEnabled' => $config->isDynamicFacetsEnabled(),
204-
'redirects' => [
205-
'enabled' => $this->instantSearchConfig->isInstantRedirectEnabled(),
206-
'onPageLoad' => in_array(InstantSearchRedirectOptions::REDIRECT_ON_PAGE_LOAD, $this->instantSearchConfig->getInstantRedirectOptions()),
207-
'onSearchAsYouType' => in_array(InstantSearchRedirectOptions::REDIRECT_ON_SEARCH_AS_YOU_TYPE, $this->instantSearchConfig->getInstantRedirectOptions()),
208-
'showSelectableRedirect' => in_array(InstantSearchRedirectOptions::SELECTABLE_REDIRECT, $this->instantSearchConfig->getInstantRedirectOptions()),
209-
'openInNewWindow' => in_array(InstantSearchRedirectOptions::OPEN_IN_NEW_WINDOW, $this->instantSearchConfig->getInstantRedirectOptions())
210-
]
211-
],
190+
'instant' => $this->getInstantSearchConfig($addToCartParams),
212191
'autocomplete' => $this->getAutocompleteConfiguration(),
213192
'landingPage' => [
214193
'query' => $this->getLandingPageQuery(),
@@ -406,6 +385,36 @@ protected function getAutocompleteConfiguration(): array
406385
];
407386
}
408387

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+
409418
protected function areCategoriesInFacets($facets)
410419
{
411420
return in_array('categories', array_column($facets, 'attribute'));

0 commit comments

Comments
 (0)