Magento – Magento2.3 : Layered Navigation issue

layered-navigationmagento2.3

When call block on custom view:

$layer=$layout->createBlock('Magento\LayeredNavigation\Block\Navigation\Category');

Exception #0 (RuntimeException): Illegal state
#0 /home/httpdocs/generated/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection/Interceptor.php(63):
Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection->addFieldToFilter('category_ids',
'169')
#1 /home/httpdocs/vendor/magento/module-catalog-search/Model/ResourceModel/Fulltext/Collection.php(479):
Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\Interceptor->addFieldToFilter('category_ids',
'169')
#2 /home/httpdocs/generated/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection/Interceptor.php(128):
Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection->addCategoryFilter(Object(Magento\Catalog\Model\Category\Interceptor))
#3 /home/httpdocs/vendor/magento/module-catalog-search/Model/Layer/Filter/Category.php(76):
Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\Interceptor->addCategoryFilter(Object(Magento\Catalog\Model\Category\Interceptor))
#4 /home/httpdocs/vendor/magento/module-layered-navigation/Block/Navigation.php(67):
Magento\CatalogSearch\Model\Layer\Filter\Category->apply(Object(Magento\Framework\App\Request\Http))
#5 /home/httpdocs/vendor/magento/framework/View/Element/AbstractBlock.php(273):
Magento\LayeredNavigation\Block\Navigation->_prepareLayout()

Best Answer

  1. By removing throw exception, you can solve the issue.
  2. Override file if it works in your case

Go to vendor\magento\module-catalog-search\Model\ResourceModel\Fulltext\Collection->addFieldToFilter() function and remove

    if ($this->searchResult !== null) {
    throw new \RuntimeException('Illegal state');
}