cancel
Showing results for 
Search instead for 
Did you mean: 

Get Sorter in layered navigation

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Get Sorter in layered navigation

Hello guys,

 

The problem is that I can't place sorter in layered navigation. If I place it I get error telling undefined method 'getAvailableOrders'.

 

I tried to place it in layered navigation like this:

/Magento_LayeredNavigation/templates/layer/view.phtml

 

<?php if ($block->canShowBlock()): ?>
<div class="block filter">
<div class="block-title filter-title">
<strong><?= /* @escapeNotVerified */ __('Shop By') ?></strong>
</div>

<div class="block-content filter-content">

// HERE INCLUDING THE SORTER
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>

<?= $block->getChildHtml('state') ?>

<?php if ($block->getLayer()->getState()->getFilters()): ?>
<div class="block-actions filter-actions">
<a href="<?= /* @escapeNotVerified */ $block->getClearUrl() ?>" class="action clear filter-clear"><span><?= /* @escapeNotVerified */ __('Clear All') ?></span></a>
</div>
<?php endif; ?>
<?php $wrapOptions = false; ?>
<?php foreach ($block->getFilters() as $filter): ?>
<?php if (!$wrapOptions): ?>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= /* @escapeNotVerified */ __('Shopping Options') ?></strong>
<dl class="filter-options" id="narrow-by-list">
<?php $wrapOptions = true; endif; ?>
<?php if ($filter->getItemsCount()): ?>
<dt role="heading" aria-level="3" class="filter-options-title"><?= $block->escapeHtml(__($filter->getName())) ?></dt>
<dd class="filter-options-content"><?= /* @escapeNotVerified */ $block->getChildBlock('renderer')->render($filter) ?></dd>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($wrapOptions): ?>
</dl>
<?php endif; ?>
</div>
</div>
<?php endif; ?>

 

1 REPLY 1

Re: Get Sorter in layered navigation

That is because the Sorter needs to block 

Magento\Catalog\Block\Product\ProductList\Toolbar

and you are just placing this in the sidebar. 
You could add a block 

<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_custom_sorter" template="Your_Custommodule::product/list/sorter.phtml">

Place it inside the layered navigation part with a referenceContainer.
and create the sorter.phtml with the code 

<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>