Skip to content

Commit e4c0927

Browse files
committed
MAGE-985 Add clickable redirect on interact option
1 parent e5c0d91 commit e4c0927

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

Block/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public function getConfiguration()
371371
'products' => __('Products'),
372372
'suggestions' => __('Suggestions'),
373373
'searchBy' => __('Search by'),
374+
'redirectSearchPrompt' => __("Continue search for"),
374375
'searchForFacetValuesPlaceholder' => __('Search for other ...'),
375376
'showMore' => __('Show more products'),
376377
'searchTitle' => __('Search results for'),

view/frontend/templates/instant/wrapper.phtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
<!-- Wrapping template -->
44
<script type="text/template" id="instant_wrapper_template">
5-
6-
75
<div id="algolia_instant_selector"
86
class="<?php echo $block->escapeHtml($block->hasFacets() ? ' with-facets' : ''); ?>">
97
<div class="row">
@@ -41,6 +39,7 @@
4139
<div class="algolia-clearfix"></div>
4240
</div>
4341
<div id="algolia-banner"></div>
42+
<div id="instant-redirect-container"></div>
4443
<div id="instant-empty-results-container"></div>
4544
<div id="instant-search-results-container"></div>
4645
</div>

view/frontend/web/css/instantsearch.v3.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,8 @@ button.ais-CurrentRefinements-delete:focus {
318318
padding: 3em 0;
319319
text-align: center;
320320
}
321+
322+
.instant-redirect {
323+
margin: 3em 0 1em 0;
324+
text-align: center;
325+
}

view/frontend/web/js/instantsearch.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,13 @@ define([
179179

180180
allWidgetConfiguration = this.configureFacets(allWidgetConfiguration);
181181

182-
// allWidgetConfiguration = this.configureRedirects(allWidgetConfiguration)
183-
184182
if (algoliaConfig.analytics.enabled) {
185183
allWidgetConfiguration.analytics = this.getAnalyticsWidget()
186184
}
187185

188186
return allWidgetConfiguration;
189187
},
190-
191-
// configureRedirects(allWidgetConfiguration) {
192-
// return allWidgetConfiguration;
193-
// },
194-
188+
195189
/**
196190
* Process a passed widget config object and add to InstantSearch
197191
* Dynamic widgets are deferred as they must be aggregated and processed separately
@@ -976,6 +970,7 @@ define([
976970
customWidgets.push(this.getSuggestionsWidget(this.minQuerySuggestions));
977971
}
978972

973+
// Placeholder for config
979974
const allowRedirects = true;
980975
if (allowRedirects) {
981976
customWidgets.push(this.getRedirectWidget());
@@ -1070,14 +1065,18 @@ define([
10701065
const uiComponnent = this;
10711066
return {
10721067
render({ results }) {
1073-
if (
1074-
results &&
1075-
results.renderingContent &&
1076-
results.renderingContent.redirect &&
1077-
!uiComponnent.hasInteracted
1078-
) {
1079-
window.location.href = results.renderingContent.redirect.url;
1068+
let content = '';
1069+
if (results && results.renderingContent) {
1070+
if (results.renderingContent.redirect) {
1071+
if (!uiComponnent.hasInteracted) {
1072+
window.location.href = results.renderingContent.redirect.url;
1073+
}
1074+
content += `<div class="instant-redirect">`;
1075+
content += `<a href="${results.renderingContent.redirect.url}">${algoliaConfig.translations.redirectSearchPrompt} "${results.query}"</a>`;
1076+
content += `</div>`;
1077+
}
10801078
}
1079+
document.querySelector('#instant-redirect-container').innerHTML = content;
10811080
},
10821081
};
10831082
},

0 commit comments

Comments
 (0)