I want to make Magento 2 filter option like this
but don't have any idea how to get max and min price range of all products in product listing page in Magento 2
thanks in advance
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI want to make Magento 2 filter option like this
but don't have any idea how to get max and min price range of all products in product listing page in Magento 2
thanks in advance
Overwrite Magento\LayeredNavigation\Block\Navigation\FilterRenderer and add following method:
/**
* Get price range
*
* @param $filter
* @return array
*/
public function getPriceRange($filter)
{
$filterPrice = array('min' => 0 , 'max'=>0);
if($filter instanceof \Magento\CatalogSearch\Model\Layer\Filter\Price) {
$priceArr = $filter->getResource()->loadPrices(10000000000);
$filterPrice['min'] = reset($priceArr);
$filterPrice['max'] = end($priceArr);
}
return $filterPrice;
}
Now inside filter.phtml try following way:
<?php if($filter instanceof Magento\CatalogSearch\Model\Layer\Filter\Price ): ?>
<?php $range = $block->getPriceRange($filter);?>