Ask your Question

PEOPLE YOU MIGHT KNOW

Pooja
Pooja

Chiplun,  India
Everest Educational
Everest Educational

Visa Consultants in Punjab

Ludhiana,  India
Vikas
Vikas

Web developer

Gurgaon,  India
Space
Space

Courier Services

Birmingham,  United Kingdom
MobileComm
MobileComm

MobileComm Professionals Inc.

Richardson,  United States

Write to us

Ask Question

Get Minimum and Maximum price of current category from product collection

Sangita Singh

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

?>
 

Sangita Singh

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