I would like to implement below REST API in magento 2
"How to retrieve which layered navigation filters are applied as like in the product list page?"
Can you please suggest me how we can achieve (or) possibilities?
In magento 1 at website level we can get applied filters at list page (list.phtml) by following snippet
$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
(and)
$appliedFilters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
But in magento 2 at api level how we can implement ?
-
Hello @NagarajuKasa Have you got any solution for this ?Aditya Shah– Aditya Shah2018年10月09日 11:53:29 +00:00Commented Oct 9, 2018 at 11:53
-
1No @adityA shahNagaraju Kasa– Nagaraju Kasa2018年10月10日 02:56:22 +00:00Commented Oct 10, 2018 at 2:56
1 Answer 1
$this->layerResolver->setCurrentCategory($id);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$fill = $objectManager->create('Magento\Catalog\Model\Layer\Category\FilterableAttributeList');
$filterList = new \Magento\Catalog\Model\Layer\FilterList($objectManager,$fill);
$filterAttributes = $filterList->getFilters($this->layerResolver);
$filterArray = array();
$i = 0;
foreach($filterAttributes as $filter){
$availablefilter = (string)$filter->getName(); //Gives Display Name of the filter such as Category,Price etc.
$items = $filter->getItems(); //Gives all available filter options in that particular filter
$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(); //Gives no. of products in each filter options
$j++;
}
if(!empty($filterValues)){
$filterArray['availablefilter'][$availablefilter] = $filterValues;
}
$i++;
}
return array($filterArray);
I Have implemented same as in list page , but not i need to develop for the search result page , how could i?
Explore related questions
See similar questions with these tags.