I have created a controller to get layered navigation but, I am facing an issue in price layered navigation price range always the same in every category 0-10000 10000-20000 etc not according to a product in the category below is my code
try {
$this->verifyRequest();
$environment = $this->emulate->startEnvironmentEmulation($this->storeId);
$category = $this->categoryId;
$objectManager = ObjectManager::getInstance();
$filterList = $objectManager->getInstance()->create(MagentoCatalogModelLayerFilterList::class,[
‘filterableAttributes’ => $this->filterableAttributes
]
);
$layer = $this->layerResolver->get();
$layer->setCurrentCategory($category);
$filters = $filterList->getFilters($layer);
$maxPrice = $layer->getProductCollection()->getMaxPrice();
$minPrice = $layer->getProductCollection()->getMinPrice();
$i = 0;
foreach($filters as $filter) {
$finalFilter['label'] = (string)$filter->getName();
$finalFilter['code'] = $filter->getRequestVar();
$items = $filter->getItems();
$filterValues = [];
$j = 0;
foreach($items as $item) {
if ($finalFilter['code'] == "color") {
$filterValues[$j]['display'] = strip_tags($item->getLabel());
$filterValues[$j]['value'] = $item->getValue();
$filterValues[$j]['count'] = $item->getCount();
$filterValues[$j]['image'] = $this->getAtributeSwatchHashcode($item->getValue());
$j++;
} else {
$filterValues[$j]['display'] = strip_tags($item->getLabel());
$filterValues[$j]['value'] = $item->getValue();
$filterValues[$j]['count'] = $item->getCount();
$j++;
}
}
if(!empty($filterValues) && count($filterValues)>1) {
$finalFilter['options'] = $filterValues;
$this->returnArray['availablefilter'][] = $finalFilter;
}
$i++;
}
$this->returnArray["success"] = true;
$this->emulate->stopEnvironmentEmulation($environment);
return $this->getJsonResponse($this->returnArray);
} catch (Exception $e) {
$this->returnArray["message"] = __($e->getMessage());
return $this->getJsonResponse($this->returnArray);
}