Skip to content

Commit 8e6f311

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

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

Block/Algolia.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
66
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
7+
use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper;
78
use Algolia\AlgoliaSearch\Helper\Configuration\PersonalizationHelper;
89
use Algolia\AlgoliaSearch\Helper\Data as CoreHelper;
910
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
@@ -40,6 +41,8 @@ class Algolia extends Template implements CollectionDataSourceInterface
4041

4142
public function __construct(
4243
protected ConfigHelper $config,
44+
protected AutocompleteHelper $autocompleteConfig,
45+
protected PersonalizationHelper $personalizationHelper,
4346
protected CatalogSearchHelper $catalogSearchHelper,
4447
protected ProductHelper $productHelper,
4548
protected Currency $currency,
@@ -53,7 +56,6 @@ public function __construct(
5356
protected CategoryHelper $categoryHelper,
5457
protected SuggestionHelper $suggestionHelper,
5558
protected LandingPageHelper $landingPageHelper,
56-
protected PersonalizationHelper $personalizationHelper,
5759
protected CheckoutSession $checkoutSession,
5860
protected DateTime $date,
5961
protected CurrentCategory $currentCategory,

Block/Configuration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ public function getConfiguration()
221221
'debounceMilliseconds' => $config->getAutocompleteDebounceMilliseconds(),
222222
'minimumCharacters' => $config->getAutocompleteMinimumCharacterLength(),
223223
'redirects' => [
224-
'enabled' => $config->isAutocompleteRedirectEnabled(),
225-
'showSelectableRedirect' => $config->getAutocompleteRedirectMode() !== AutocompleteRedirectMode::SUBMIT_ONLY,
226-
'showHitsWithRedirect' => $config->getAutocompleteRedirectMode() !== AutocompleteRedirectMode::SELECTABLE_REDIRECT,
227-
'openInNewWindow' => $config->isAutocompleteRedirectInNewWindowEnabled()
224+
'enabled' => $this->autocompleteConfig->isAutocompleteRedirectEnabled(),
225+
'showSelectableRedirect' => $this->autocompleteConfig->getAutocompleteRedirectMode() !== AutocompleteRedirectMode::SUBMIT_ONLY,
226+
'showHitsWithRedirect' => $this->autocompleteConfig->getAutocompleteRedirectMode() !== AutocompleteRedirectMode::SELECTABLE_REDIRECT,
227+
'openInNewWindow' => $this->autocompleteConfig->isAutocompleteRedirectInNewWindowEnabled()
228228
]
229229
],
230230
'landingPage' => [

Helper/ConfigHelper.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ class ConfigHelper
6363
public const AUTOCOMPLETE_DEBOUNCE_MILLISEC = 'algoliasearch_autocomplete/autocomplete/debounce_millisec';
6464
public const AUTOCOMPLETE_MINIMUM_CHAR_LENGTH = 'algoliasearch_autocomplete/autocomplete/minimum_char_length';
6565

66-
public const IS_AUTOCOMPLETE_REDIRECT_ENABLED = 'algoliasearch_autocomplete/redirects/enable';
67-
public const AUTOCOMPLETE_REDIRECT_MODE = 'algoliasearch_autocomplete/redirects/mode';
68-
public const AUTOCOMPLETE_OPEN_REDIRECT_IN_NEW_WINDOW = 'algoliasearch_autocomplete/redirects/target';
69-
7066
public const PRODUCT_ATTRIBUTES = 'algoliasearch_products/products/product_additional_attributes';
7167
public const PRODUCT_CUSTOM_RANKING = 'algoliasearch_products/products/custom_ranking_product_attributes';
7268
public const USE_ADAPTIVE_IMAGE = 'algoliasearch_products/products/use_adaptive_image';
@@ -1067,26 +1063,6 @@ public function getAutocompleteMinimumCharacterLength(?int $storeId = null): int
10671063
);
10681064
}
10691065

1070-
public function isAutocompleteRedirectEnabled(?int $storeId = null): bool
1071-
{
1072-
return $this->configInterface->isSetFlag(self::IS_AUTOCOMPLETE_REDIRECT_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
1073-
}
1074-
1075-
public function getAutocompleteRedirectMode(?int $storeId = null): int
1076-
{
1077-
return (int) $this->configInterface->getValue(
1078-
self::AUTOCOMPLETE_REDIRECT_MODE,
1079-
ScopeInterface::SCOPE_STORE,
1080-
$storeId
1081-
);
1082-
}
1083-
1084-
public function isAutocompleteRedirectInNewWindowEnabled($storeId = null): bool
1085-
{
1086-
return $this->configInterface->isSetFlag(self::AUTOCOMPLETE_OPEN_REDIRECT_IN_NEW_WINDOW, ScopeInterface::SCOPE_STORE, $storeId);
1087-
}
1088-
1089-
10901066
public function isInstantRedirectEnabled(?int $storeId = null): bool
10911067
{
10921068
return $this->configInterface->isSetFlag(self::IS_INSTANT_REDIRECT_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 AutocompleteHelper
9+
{
10+
public const IS_AUTOCOMPLETE_REDIRECT_ENABLED = 'algoliasearch_autocomplete/redirects/enable';
11+
public const AUTOCOMPLETE_REDIRECT_MODE = 'algoliasearch_autocomplete/redirects/mode';
12+
public const AUTOCOMPLETE_OPEN_REDIRECT_IN_NEW_WINDOW = 'algoliasearch_autocomplete/redirects/target';
13+
14+
public function __construct(
15+
protected ScopeConfigInterface $configInterface,
16+
) {}
17+
public function isAutocompleteRedirectEnabled(?int $storeId = null): bool
18+
{
19+
return $this->configInterface->isSetFlag(self::IS_AUTOCOMPLETE_REDIRECT_ENABLED, ScopeInterface::SCOPE_STORE, $storeId);
20+
}
21+
22+
public function getAutocompleteRedirectMode(?int $storeId = null): int
23+
{
24+
return (int) $this->configInterface->getValue(
25+
self::AUTOCOMPLETE_REDIRECT_MODE,
26+
ScopeInterface::SCOPE_STORE,
27+
$storeId
28+
);
29+
}
30+
31+
public function isAutocompleteRedirectInNewWindowEnabled($storeId = null): bool
32+
{
33+
return $this->configInterface->isSetFlag(self::AUTOCOMPLETE_OPEN_REDIRECT_IN_NEW_WINDOW, ScopeInterface::SCOPE_STORE, $storeId);
34+
}
35+
36+
}

0 commit comments

Comments
 (0)