<?php
namespace handymustFilterModel;
use handymustFilterApiFilterInterface;
use MagentoCatalogModelLayerResolver;
use MagentoCatalogModelLayerCategoryFilterableAttributeList;
use MagentoCatalogModelLayerFilterList;
use MagentoFrameworkExceptionLocalizedException;
class Filter implements FilterInterface
{
protected $layerResolver;
protected $filterList;
protected $filterableAttributeList;
public function __construct(
Resolver $layerResolver,
FilterList $filterList,
FilterableAttributeList $filterableAttributeList
)
{
$this->layerResolver = $layerResolver;
$this->filterList = $filterList;
$this->filterableAttributeList = $filterableAttributeList;
}
/**
* @throws LocalizedException
*/
public function getByCategoryId($categoryId)
{
// Initialize layer and set the current category
$layer = $this->layerResolver->get();
$layer->setCurrentCategory($categoryId);
// Get the list of filterable attributes for the current category
$filterAttributes = $this->filterList->getFilters($layer);
$filterValues = [];
foreach ($filterAttributes as $filter) {
$attributeCode = $filter->getRequestVar();
$items = $filter->getItems();
$filterValues[$attributeCode] = [];
foreach ($items as $item) {
$label = $item->getLabel();
$count = $item->getCount();
$value = $item->getValue();
$filterValues[$attributeCode][] = [
'label' => $label,
'count' => $count,
'value' => $value,
];
}
}
return $filterValues;
}
}
errors are in the screenshot: