From 97fa1bd34db4f9d850678cc9d7e73abf82eef9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20FOUCRET?= Date: Fri, 23 Feb 2018 13:08:26 +0100 Subject: [PATCH] Fix broken layered navigation when using 1 column layout. --- .../Block/Navigation.php | 52 ++++++++++++++----- .../view/frontend/templates/layer/view.phtml | 18 +++---- .../view/frontend/web/css/source/_module.less | 14 +++++ 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/module-elasticsuite-catalog/Block/Navigation.php b/src/module-elasticsuite-catalog/Block/Navigation.php index 41b815777..6fefb8982 100644 --- a/src/module-elasticsuite-catalog/Block/Navigation.php +++ b/src/module-elasticsuite-catalog/Block/Navigation.php @@ -40,6 +40,16 @@ class Navigation extends \Magento\LayeredNavigation\Block\Navigation */ private $relevantFilterList; + /** + * @var string[] + */ + private $inlineLayouts = ['1column']; + + /** + * @var string|NULL + */ + private $pageLayout; + /** * Navigation constructor. * @@ -63,7 +73,7 @@ public function __construct( array $data ) { parent::__construct($context, $layerResolver, $filterList, $visibilityFlag, $data); - + $this->pageLayout = $context->getPageConfig()->getPageLayout(); $this->objectManager = $objectManager; $this->moduleManager = $moduleManager; $this->relevantFilterList = $relevantFilterList; @@ -78,22 +88,24 @@ public function __construct( */ public function canShowBlock() { + $canShowBlock = parent::canShowBlock(); + if ($this->moduleManager->isEnabled('Magento_Staging')) { try { $versionManager = $this->objectManager->get('\Magento\Staging\Model\VersionManager'); - return parent::canShowBlock() && !$versionManager->isPreviewVersion(); + $canShowBlock = $canShowBlock && !$versionManager->isPreviewVersion(); } catch (\Exception $exception) { - return parent::canShowBlock(); + ; } } if ($this->getLayer() instanceof \Magento\Catalog\Model\Layer\Category && $this->getLayer()->getCurrentCategory()->getDisplayMode() === \Magento\Catalog\Model\Category::DM_PAGE) { - return false; + $canShowBlock = false; } - return parent::canShowBlock(); + return $canShowBlock; } /** @@ -106,14 +118,18 @@ public function canShowBlock() */ public function getActiveFilters() { - $requestParams = array_keys($this->getRequest()->getParams()); - $displayedFilters = $this->getDisplayedFilters(); - $expandedFacets = $this->_scopeConfig->getValue(self::DEFAULT_EXPANDED_FACETS_COUNT_CONFIG_XML_PATH); - $activeFilters = range(0, min(count($displayedFilters), $expandedFacets) - 1); - - foreach ($displayedFilters as $index => $filter) { - if (in_array($filter->getRequestVar(), $requestParams)) { - $activeFilters[] = $index; + $activeFilters = []; + + if (!$this->isInline()) { + $requestParams = array_keys($this->getRequest()->getParams()); + $displayedFilters = $this->getDisplayedFilters(); + $expandedFacets = $this->_scopeConfig->getValue(self::DEFAULT_EXPANDED_FACETS_COUNT_CONFIG_XML_PATH); + $activeFilters = range(0, min(count($displayedFilters), $expandedFacets) - 1); + + foreach ($displayedFilters as $index => $filter) { + if (in_array($filter->getRequestVar(), $requestParams)) { + $activeFilters[] = $index; + } } } @@ -137,6 +153,16 @@ function ($filter) { return array_values($displayedFilters); } + /** + * Indicates if the block is displayed inline or not. + * + * @return boolean + */ + public function isInline() + { + return in_array($this->pageLayout, $this->inlineLayouts); + } + /** * @SuppressWarnings(PHPMD.CamelCaseMethodName) * diff --git a/src/module-elasticsuite-catalog/view/frontend/templates/layer/view.phtml b/src/module-elasticsuite-catalog/view/frontend/templates/layer/view.phtml index fe8850f45..12805f4e3 100644 --- a/src/module-elasticsuite-catalog/view/frontend/templates/layer/view.phtml +++ b/src/module-elasticsuite-catalog/view/frontend/templates/layer/view.phtml @@ -21,12 +21,10 @@ ?> canShowBlock()) : ?> - getFilters());?> getActiveFilters(); ?> -
getLayer()->getState()->getFilters()) ?> -
+
@@ -42,18 +40,18 @@ getFilters() as $filter) : ?> getItemsCount()) : ?> - -
+ +
-
getName()) ?>
-
-
getChildBlock('renderer')->render($filter); ?>
-
+
+
getName()) ?>
+
getChildBlock('renderer')->render($filter) ?>
+
-
+