Skip to content

Commit c4c62db

Browse files
committed
MAGE-1015 Remove InstantSearch from global deps
1 parent fb57455 commit c4c62db

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Block/Configuration.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Configuration extends Algolia implements CollectionDataSourceInterface
1313
//Placeholder for future implementation (requires custom renderer for hierarchicalMenu widget)
1414
private const IS_CATEGORY_NAVIGATION_ENABLED = false;
1515

16-
public function isSearchPage()
16+
public function isSearchPage(): bool
1717
{
1818
if ($this->getConfigHelper()->isInstantEnabled()) {
1919
/** @var Http $request */
@@ -80,8 +80,6 @@ public function getConfiguration()
8080

8181
$suggestionHelper = $this->getSuggestionHelper();
8282

83-
$productHelper = $this->getProductHelper();
84-
8583
$algoliaHelper = $this->getAlgoliaHelper();
8684

8785
$persoHelper = $this->getPersonalizationHelper();
@@ -254,7 +252,7 @@ public function getConfiguration()
254252
'attributeFilter' => $attributesToFilter,
255253
'facets' => $facets,
256254
'areCategoriesInFacets' => $areCategoriesInFacets,
257-
'hitsPerPage' => (int) $config->getNumberOfProductResults(),
255+
'hitsPerPage' => $config->getNumberOfProductResults(),
258256
'sortingIndices' => array_values($this->sortingTransformer->getSortingIndices(
259257
$this->getStoreId(),
260258
$customerGroupId
@@ -421,7 +419,7 @@ protected function getOrderedProductIds(ConfigHelper $configHelper, Http $reques
421419
return $ids;
422420
}
423421

424-
protected function isLandingPage()
422+
protected function isLandingPage(): bool
425423
{
426424
return $this->getRequest()->getFullActionName() === 'algolia_landingpage_view';
427425
}
@@ -440,4 +438,15 @@ protected function getLandingPageConfiguration()
440438
{
441439
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]);
442440
}
441+
442+
public function canLoadInstantSearch(): bool
443+
{
444+
return $this->getConfigHelper()->isInstantEnabled()
445+
&& $this->isProductListingPage();
446+
}
447+
448+
protected function isProductListingPage(): bool
449+
{
450+
return $this->isSearchPage() || $this->isLandingPage();
451+
}
443452
}

view/frontend/requirejs-config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const config = {
5555

5656
},
5757
deps : [
58-
'algoliaInstantSearch',
5958
'algoliaInsights'
6059
],
6160
config: {

view/frontend/templates/internals/configuration.phtml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $configuration = $block->getConfiguration();
77
if (class_exists('\Magento\Framework\View\Helper\SecureHtmlRenderer')) : ?>
88
<?php
99
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
10-
if ($configuration['instant']['enabled'] === true && $configuration['isSearchPage'] === true) {
10+
if ($block->canLoadInstantSearch()) {
1111
$css = /* @noEscape */ $secureRenderer->renderTag('style', [], $configuration['instant']['selector'] . ' {display:none}', false);
1212
/* @noEscape */ echo $secureRenderer->renderTag('script', [], 'document.write(\'' . $css . '\');' , false);
1313
}
@@ -17,7 +17,7 @@ if (class_exists('\Magento\Framework\View\Helper\SecureHtmlRenderer')) : ?>
1717
<?php else: ?>
1818
<script>
1919
<?php
20-
if ($configuration['instant']['enabled'] === true && $configuration['isSearchPage'] === true) :
20+
if ($block->canLoadInstantSearch()):
2121
$css = '<style type="text/css">' . $configuration['instant']['selector'] . ' {display:none}</style>';
2222
?>
2323
// Hide the instant-search selector ASAP to remove flickering. Will be re-displayed later with JS.
@@ -29,3 +29,14 @@ if (class_exists('\Magento\Framework\View\Helper\SecureHtmlRenderer')) : ?>
2929
window.algoliaConfig = <?php /* @noEscape */ echo json_encode($configuration); ?>;
3030
</script>
3131
<?php endif; ?>
32+
33+
34+
<?php if ($block->canLoadInstantSearch()) : ?>
35+
<script type="text/x-magento-init">
36+
{
37+
"*": {
38+
"algoliaInstantSearch": {}
39+
}
40+
}
41+
</script>
42+
<?php endif;?>

0 commit comments

Comments
 (0)