0

I want to make Magento 2 filter option like this

enter image description here

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

0

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);?>

| improve this answer | |
  • I don't do like this, i only want to get all price range in layered navigation – Shaielndra Gupta Jan 27 '19 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.