Skip to content

magento 2 layer navigation by categoryId i’m getting below error

“message”: “No record found with %fieldName = %fieldValue”,
“parameters”: {
“fieldName”: “id”,
“fieldValue”: “0”
},

<?php
        
        namespace handymustFilterModel;
        
        use handymustFilterApiFilterInterface;
        use MagentoFrameworkExceptionLocalizedException;
        
        class Filter implements FilterInterface
        {
            protected $_layerResolver;
        
            public function __construct(
                MagentoCatalogModelLayerResolver $layerResolver
            )
            {
                $this->_layerResolver = $layerResolver->get();
            }
        
            /**
             * {@inheritdoc}
             * @throws LocalizedException
             */
            public function getFiltersByCategoryId($categoryId)
            {
                $this->_layerResolver->setCurrentCategory($categoryId);
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $fill = $objectManager->create('MagentoCatalogModelLayerCategoryFilterableAttributeList');
                $filterList = new MagentoCatalogModelLayerFilterList($objectManager, $fill);
                $filterAttributes = $filterList->getFilters($this->_layerResolver);
                $filterArray = array();
                $i = 0;
        
                foreach ($filterAttributes as $filter) {
                    $availablefilter = (string)$filter->getName();
                    $items = $filter->getItems();
                    $filterValues = array();
                    $j = 0;
        
                    foreach ($items as $item) {
                        $filterValues[$j]['display'] = strip_tags($item->getLabel());
                        $filterValues[$j]['label'] = $item->getValue();
                        $filterValues[$j]['count'] = $item->getCount();
                        $j++;
                    }
        
                    if (!empty($filterValues)) {
                        $filterArray['availablefilter'][$availablefilter] = $filterValues;
                    }
        
                    $i++;
                }
        
                return $filterArray;
            }
        }