Get Minimum and Maximum price of current category from product collection

<?php

namespace Letsknowit\Priceslider\Block;

use Magento\Catalog\Model\Layer\Filter\Price;
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
use Magento\Framework\View\Element\Template;
use Magento\LayeredNavigation\Block\Navigation\FilterRendererInterface;

class FilterRenderer extends \Magento\LayeredNavigation\Block\Navigation\FilterRenderer {
    
    protected $registry;

    protected $request;

    protected $productCollection;

    protected $scopeConfig;

    public function __construct(
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\RequestInterface $request,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection,
         \Magento\Backend\Block\Template\Context $context,        
        array $data = [ ]
    ) {
       $this->registry = $registry; 
       $this->request = $request;
       $this->scopeConfig = $scopeConfig;
       $this->productCollection = $productCollection;       
       parent::__construct($context, $data);

    }

    public function getPriceRange($filter) {
          
       $category = $this->registry->registry('current_category');

       $ProductFactory = $this->productCollection->addAttributeToSelect('price')->setOrder('price', 'DESC')->addCategoryFilter($category); 

        $maxPrice = $ProductFactory->getMaxPrice();
        $minPrice = $ProductFactory->getMinPrice();       
        $filterprice = array('min' => $minPrice, 'max' => $maxPrice);
       
        return $filterprice;
    }

?>
 

0   0
Sangita Singh
profile 12th March 2026

Kindly balanced in difficulty and flow, Slope Game 2 offers a welcoming arcade experience that helps players feel comfortable while improving control, as smooth physics and fair pacing encourage confidence, patience, and steady skill growth through repeated and enjoyable play sessions over time.

profile Suman 7th March 2026

The rising demand for Delhi call girls is a reflection of the importance that people attach to companionship in the midst of a busy city.

Chanakyapuri Escorts Service || Escorts Service Greater Kailash || Escorts Service in Saket || Karol Bagh Escorts || Escorts in Rohini ||

profile Mubashar 3rd March 2026

Knowing the minimum and maximum prices in a product category helps customers make informed choices and saves time while browsing. It’s especially useful for exploring a menu or collection, where options can vary widely in flavor, size, or specialty. Clear price ranges give users confidence and improve the overall experience, making it easier to find exactly what they want. https://besturdunovel.com/

profile Mubashar 3rd March 2026

Getting the minimum and maximum price of the current category from a product collection is a smart way to improve filtering and enhance the user experience. It helps visitors quickly understand the price range and make better purchasing decisions without scrolling endlessly. Clear pricing insights not only build trust but also make navigation smoother and more efficient. Organizing and presenting information properly always adds value for users exploring different options.https://7brewwmenu.com/

profile thomas 5th February 2026

You can loop through the products in the selected collection, collect their price values, and then apply a min and max calculation before displaying the result. This method keeps the price range accurate even when items are added, removed, or updated. It works especially well for categories with frequently changing prices or limited-time items. https://thepandaexpressmenu.com/
 

profile jon 23rd January 2026

For current category min/max price, filter products by category first, then use an aggregate query with $group + $min and $max on the price field. This is fast and perfect for showing a price range filter on category pages in fashion stores. https://apricocia.com/

profile Jack 23rd January 2026

Fetching minimum and maximum prices from a product collection is a smart way to improve category filtering and give users quick pricing context. This approach works especially well for menu-style listings where visitors want to compare options at a glance without opening each item. Clear price ranges make navigation smoother and help users decide faster while browsing structured collections. https://theolivegardenmenu.com/

profile james 23rd January 2026

By calculating min and max prices directly from the active product collection instead of relying on static values. It keeps filters accurate when products or variants change and avoids mismatches on category pages. The same idea applies in other tools that work with dynamic ranges and profiles, like configuration-driven software. A similar concept is explained here: https://orcaslicer.pro

profile Jaxon 19th January 2026

Getting accurate minimum and maximum prices from a product collection really comes down to clean logic and consistent data handling, especially when values keep changing. I’ve used a similar structured approach when tracking totals and ranges with time-based data, and tools like this hours worked calculator explain that mindset well: https://calculadoradehorasgratis.com.br/

profile Nora 13th January 2026

The Updated DQ Menu USA 2026 brings new flavors along with classic favorites fans already love. From Blizzards to burgers and treats, the menu reflects fresh updates and seasonal options. Always check the official menu to get the latest prices and items.

profile X 24th December 2025

When dealing with minimum and maximum price logic in a product collection, it really helps users quickly understand the value range before making a choice. I’ve seen a similar mindset in content platforms, where people compare paid subscriptions versus free alternatives. For example, while exploring media apps, I came across a detailed breakdown of feature access and limits here: https://theytpremium.com/

profile samuel 23rd December 2025

You can simplify this by keeping your category data consistent and letting the query calculate min and max dynamically instead of hard-coding values. I ran into a similar setup while structuring app version details for comparisons, and this approach saved a lot of cleanup later shared a related example here if it help https://mtmanagersapk.com/

profile james 13th December 2025

The key is to narrow the collection to the exact category first, then run min and max calculations on that filtered data. This avoids issues with variants or mixed pricing. I use a similar structured approach when organizing skill-based learning resources, where clear grouping makes ranges easier to manage. You can see a practical example of this kind of organization here: https://www.zahidmuzaffarkhan.com/

profile olivia 13th December 2025

Getting the minimum and maximum price from a product collection is much easier if the data is clean and well-structured. Clear logic and consistent fields make aggregation simple. Similarly, tools that keep workflows straightforward are always effective-for example, this Pinterest video downloader works just by copy-pasting the link: https://pinterestdownloader.com.br/

profile olivia 10th November 2025

the key is to filter the product collection by that category ID before running any price functions. If the collection isn’t filtered first, you’ll end up with global values instead of category-specific ones. In most frameworks, you can apply a category filter, select the price column. https://apkcineema.com.br/

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site