Skip to content

Commit

Permalink
Fix broken layered navigation when using 1 column layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien FOUCRET committed Feb 23, 2018
1 parent ee1b8ed commit 97fa1bd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 23 deletions.
52 changes: 39 additions & 13 deletions src/module-elasticsuite-catalog/Block/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
}

Expand All @@ -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)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
?>

<?php if ($block->canShowBlock()) : ?>
<?php $filters = count($block->getFilters());?>
<?php $activeFilters = $block->getActiveFilters(); ?>
<?php /*$activeFilters = "[0, 1, 2]" ;*/?>
<div class="block filter" id="layered-filter-block" data-mage-init='{"collapsible":{"openedState": "active", "collapsible": true, "active": false, "collateral": { "openedState": "filter-active", "element": "body" } }}'>
<?php $filtered = count($block->getLayer()->getState()->getFilters()) ?>
<div class="block-title filter-title" data-count="<?php /* @escapeNotVerified */ echo $filtered; ?>">
<div class="block-title filter-title" data-count="<?= /* @escapeNotVerified */ $filtered ?>">
<strong data-role="title"><?php /* @escapeNotVerified */ echo __('Shop By') ?></strong>
</div>

Expand All @@ -42,18 +40,18 @@
<?php foreach ($block->getFilters() as $filter) : ?>
<?php if ($filter->getItemsCount()) : ?>
<?php if (!$wrapOptions) : ?>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
<dl class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": <?php /* @noEscape */ echo $activeFilters; ?>, "multipleCollapsible": true}}'>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= /* @escapeNotVerified */ __('Shopping Options') ?></strong>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": <?php /* @noEscape */ echo $activeFilters; ?>, "multipleCollapsible": <?= /* @noEscape */ $block->isInline() ? "false" : "true"; ?>}}'>
<?php $wrapOptions = true;?>
<?php endif; ?>
<dt data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></dt>
<dd data-role="collapsible" class="filter-options-item">
<div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
</dd>
<div data-role="collapsible" class="filter-options-item">
<div data-role="title" class="filter-options-title"><?= /* @escapeNotVerified */ __($filter->getName()) ?></div>
<div data-role="content" class="filter-options-content"><?= /* @escapeNotVerified */ $block->getChildBlock('renderer')->render($filter) ?></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($wrapOptions) : ?>
</dl>
</div>
<?php else : ?>
<script>
require([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,17 @@
}
}
}

.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
.page-layout-1column {
.filter-options {
.filter {
&-options {
&-content {
padding: @indent__s;
}
}
}
}
}
}

0 comments on commit 97fa1bd

Please sign in to comment.