Skip to content

Commit d96aab6

Browse files
committed
MAGE-986 Move new config options to discrete InstantSearch config helper
1 parent 8e6f311 commit d96aab6

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

Block/Algolia.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
66
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
77
use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper;
8+
use Algolia\AlgoliaSearch\Helper\Configuration\InstantSearchHelper;
89
use Algolia\AlgoliaSearch\Helper\Configuration\PersonalizationHelper;
910
use Algolia\AlgoliaSearch\Helper\Data as CoreHelper;
1011
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
@@ -42,6 +43,7 @@ class Algolia extends Template implements CollectionDataSourceInterface
4243
public function __construct(
4344
protected ConfigHelper $config,
4445
protected AutocompleteHelper $autocompleteConfig,
46+
protected InstantSearchHelper $instantSearchConfig,
4547
protected PersonalizationHelper $personalizationHelper,
4648
protected CatalogSearchHelper $catalogSearchHelper,
4749
protected ProductHelper $productHelper,

Block/Configuration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ public function getConfiguration()
202202
'hidePagination' => $config->hidePaginationInInstantSearchPage(),
203203
'isDynamicFacetsEnabled' => $config->isDynamicFacetsEnabled(),
204204
'redirects' => [
205-
'enabled' => $config->isInstantRedirectEnabled(),
206-
'onPageLoad' => in_array(InstantSearchRedirectOptions::REDIRECT_ON_PAGE_LOAD, $config->getInstantRedirectOptions()),
207-
'onSearchAsYouType' => in_array(InstantSearchRedirectOptions::REDIRECT_ON_SEARCH_AS_YOU_TYPE, $config->getInstantRedirectOptions()),
208-
'showSelectableRedirect' => in_array(InstantSearchRedirectOptions::SELECTABLE_REDIRECT, $config->getInstantRedirectOptions()),
209-
'openInNewWindow' => in_array(InstantSearchRedirectOptions::OPEN_IN_NEW_WINDOW, $config->getInstantRedirectOptions())
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())
210210
]
211211
],
212212
'autocomplete' => [

Helper/ConfigHelper.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class ConfigHelper
4747
public const INFINITE_SCROLL_ENABLE = 'algoliasearch_instant/instant_options/infinite_scroll_enable';
4848
public const HIDE_PAGINATION = 'algoliasearch_instant/instant_options/hide_pagination';
4949

50-
public const IS_INSTANT_REDIRECT_ENABLED = 'algoliasearch_instant/instant_redirects/enable';
51-
public const INSTANT_REDIRECT_OPTIONS = 'algoliasearch_instant/instant_redirects/options';
52-
5350
public const IS_POPUP_ENABLED = 'algoliasearch_autocomplete/autocomplete/is_popup_enabled';
5451
public const NB_OF_PRODUCTS_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_products_suggestions';
5552
public const NB_OF_CATEGORIES_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_categories_suggestions';
@@ -1063,21 +1060,6 @@ public function getAutocompleteMinimumCharacterLength(?int $storeId = null): int
10631060
);
10641061
}
10651062

1066-
public function isInstantRedirectEnabled(?int $storeId = null): bool
1067-
{
1068-
return $this->configInterface->isSetFlag(self::IS_INSTANT_REDIRECT_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
1069-
}
1070-
1071-
public function getInstantRedirectOptions(?int $storeId = null): array
1072-
{
1073-
$value = $this->configInterface->getValue(
1074-
self::INSTANT_REDIRECT_OPTIONS,
1075-
ScopeInterface::SCOPE_STORE,
1076-
$storeId
1077-
);
1078-
return empty($value) ? [] : explode(',', $value);
1079-
}
1080-
10811063
/**
10821064
* @param $originalIndexName
10831065
* @param $storeId
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Helper\Configuration;
4+
5+
use Magento\Framework\App\Config\ScopeConfigInterface;
6+
use Magento\Store\Model\ScopeInterface;
7+
8+
class InstantSearchHelper
9+
{
10+
public const IS_INSTANT_REDIRECT_ENABLED = 'algoliasearch_instant/instant_redirects/enable';
11+
public const INSTANT_REDIRECT_OPTIONS = 'algoliasearch_instant/instant_redirects/options';
12+
13+
public function __construct(
14+
protected ScopeConfigInterface $configInterface,
15+
) {}
16+
17+
public function isInstantRedirectEnabled(?int $storeId = null): bool
18+
{
19+
return $this->configInterface->isSetFlag(self::IS_INSTANT_REDIRECT_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
20+
}
21+
22+
public function getInstantRedirectOptions(?int $storeId = null): array
23+
{
24+
$value = $this->configInterface->getValue(
25+
self::INSTANT_REDIRECT_OPTIONS,
26+
ScopeInterface::SCOPE_STORE,
27+
$storeId
28+
);
29+
return empty($value) ? [] : explode(',', $value);
30+
}
31+
}

0 commit comments

Comments
 (0)