Skip to content

Commit 13e103e

Browse files
committed
MAGE-986 Add front end model for InstantSearch redirect options
1 parent b35fe40 commit 13e103e

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Block\Adminhtml\System\Config\Form\Field;
4+
5+
use Magento\Config\Block\System\Config\Form\Field;
6+
use Magento\Framework\Data\Form\Element\AbstractElement;
7+
8+
class Checkboxes extends Field
9+
{
10+
protected function _getElementHtml(AbstractElement $element)
11+
{
12+
$html = '';
13+
$elementId = $element->getHtmlId();
14+
$name = $element->getName();
15+
$options = $element->getValues();
16+
$values = $element->getValue() ? explode(',', $element->getValue()) : []; // store as CSV in config
17+
18+
foreach ($options as $option) {
19+
$value = $option['value'];
20+
$label = $option['label'];
21+
$checked = in_array($value, $values) ? 'checked' : '';
22+
$html .= '<label style="display:block">';
23+
$html .= sprintf(
24+
'<input type="checkbox" name="%s[]" value="%s" %s /> %s',
25+
$name,
26+
$value,
27+
$checked,
28+
$label
29+
);
30+
$html .= '</label>';
31+
}
32+
33+
return $html;
34+
}
35+
}

Model/Source/AutocompleteRedirectMode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AutocompleteRedirectMode implements OptionSourceInterface
1313
/** @return array */
1414
public function toOptionArray()
1515
{
16-
$options = [
16+
return [
1717
[
1818
'value' => self::SUBMIT_ONLY,
1919
'label' => __('Do not display the redirect (handle on form submit only)'),
@@ -27,7 +27,5 @@ public function toOptionArray()
2727
'label' => __('Display both search hits and a selectable redirect'),
2828
]
2929
];
30-
31-
return $options;
3230
}
3331
}
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\Model\Source;
4+
5+
use Magento\Framework\Data\OptionSourceInterface;
6+
7+
class InstantSearchRedirectOptions implements OptionSourceInterface
8+
{
9+
public const REDIRECT_ON_PAGE_LOAD = 1;
10+
public const REDIRECT_ON_SEARCH_AS_YOU_TYPE = 2;
11+
public const SELECTABLE_REDIRECT = 3;
12+
public const OPEN_IN_NEW_WINDOW = 4;
13+
14+
/** @return array */
15+
public function toOptionArray()
16+
{
17+
return [
18+
[
19+
'value' => self::REDIRECT_ON_PAGE_LOAD,
20+
'label' => __('Redirect on page load (if InstantSearch loads with a redirect, immediately take the user to that URL.)'),
21+
],
22+
[
23+
'value' => self::REDIRECT_ON_SEARCH_AS_YOU_TYPE,
24+
'label' => __('Trigger redirect on "search as you type"'),
25+
],
26+
[
27+
'value' => self::SELECTABLE_REDIRECT,
28+
'label' => __('Display the redirect as a selectable item above search result hits'),
29+
],
30+
[
31+
'value' => self::OPEN_IN_NEW_WINDOW,
32+
'label' => __('Open redirect URL in a new window (applies to clickable links only)'),
33+
]
34+
];
35+
}
36+
}

etc/adminhtml/system.xml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
335335
<comment>
336336
<![CDATA[
337-
When enabled, Algolia-powered search results and listing pages can be redirected to a different URL based on rules configured in either the Dashboard or Merchandising Studio.
337+
When enabled, Autocomplete can redirect searches to a different URL based on rules configured in either the Dashboard or Merchandising Studio.
338338
]]>
339339
</comment>
340340
</field>
@@ -343,7 +343,7 @@
343343
<source_model>Algolia\AlgoliaSearch\Model\Source\AutocompleteRedirectMode</source_model>
344344
<comment>
345345
<![CDATA[
346-
Use this setting to configure how redirects behave with Autocomplete.
346+
Use this setting to configure how redirects behave within Autocomplete.
347347
]]>
348348
</comment>
349349
<depends><field id="enable">1</field></depends>
@@ -555,6 +555,25 @@
555555
</comment>
556556
</field>
557557
</group>
558+
<group id="instant_redirects" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
559+
<label>Redirects</label>
560+
<attribute type="expanded">1</attribute>
561+
<field id="enable" translate="label comment" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
562+
<label>Enable redirects</label>
563+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
564+
<comment>
565+
<![CDATA[
566+
When enabled, InstantSearch powered pages can be redirected to a different URL based on rules configured in either the Dashboard or Merchandising Studio.
567+
]]>
568+
</comment>
569+
</field>
570+
<field id="options" translate="label comment" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
571+
<label>Redirect options</label>
572+
<frontend_model>Algolia\AlgoliaSearch\Block\Adminhtml\System\Config\Form\Field\Checkboxes</frontend_model>
573+
<source_model>Algolia\AlgoliaSearch\Model\Source\InstantSearchRedirectOptions</source_model>
574+
<depends><field id="enable">1</field></depends>
575+
</field>
576+
</group>
558577
</section>
559578
<section id="algoliasearch_products" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
560579
<label>Products</label>

etc/config.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</autocomplete>
2929
<redirects>
3030
<enable>1</enable>
31-
<mode>0</mode>
31+
<mode>1</mode>
3232
<target>0</target>
3333
</redirects>
3434
</algoliasearch_autocomplete>
@@ -45,6 +45,10 @@
4545
<instantsearch_searchbox>1</instantsearch_searchbox>
4646
<hide_pagination>0</hide_pagination>
4747
</instant_options>
48+
<instant_redirects>
49+
<enable>1</enable>
50+
<options>1,3</options>
51+
</instant_redirects>
4852
</algoliasearch_instant>
4953
<algoliasearch_products>
5054
<products>

0 commit comments

Comments
 (0)