public function apply(\Magento\Framework\App\RequestInterface $request)
    {
        /**
         * Filter must be string: $fromPrice-$toPrice
         */
        $filter = $request->getParam($this->getRequestVar());

        if ($filter && !is_array($filter)) {
            $filterParams = explode(',', $filter);
            $filter = $this->dataProvider->validateFilter($filterParams[0]);
            if ($filter) {
                $this->dataProvider->setInterval($filter);
                $priorFilters = $this->dataProvider->getPriorFilters($filterParams);
                if ($priorFilters) {
                    $this->dataProvider->setPriorIntervals($priorFilters);
                }

                list($fromValue, $toValue) = $filter;
                $this->setCurrentValue(['from' => $fromValue, 'to' => $toValue]);

                $bounds = array_filter(['gte' => $fromValue, 'lt' => $toValue]);

                $this->getLayer()->getProductCollection()->addFieldToFilter(
                    $this->getAttributeModel()->getAttributeCode(),
                    $this->getRangeCondition($bounds)
                );

                $this->getLayer()->getState()->addFilter(
                    $this->_createItem($this->_renderRangeLabel(empty($fromValue) ? 0 : $fromValue, $toValue), $filter)
                );
            }
        }

        return $this;
    }
public function apply(\Magento\Framework\App\RequestInterface $request)
    {
        /**
         * Filter must be string: $fromPrice-$toPrice
         */
        $filter = $request->getParam($this->getRequestVar());

        if ($filter && !is_array($filter)) {
            $filterParams = explode(',', $filter);
            $filter = $this->dataProvider->validateFilter($filterParams[0]);
            if ($filter) {
                $this->dataProvider->setInterval($filter);
                $priorFilters = $this->dataProvider->getPriorFilters($filterParams);
                if ($priorFilters) {
                    $this->dataProvider->setPriorIntervals($priorFilters);
                }

                list($fromValue, $toValue) = $filter;
                $this->setCurrentValue(['from' => $fromValue, 'to' => $toValue]);

                $bounds = array_filter(['gte' => $fromValue, 'lt' => $toValue]);

                $this->getLayer()->getProductCollection()->addFieldToFilter(
                    $this->getAttributeModel()->getAttributeCode(),
                    $this->getRangeCondition($bounds)
                );

                $this->getLayer()->getState()->addFilter(
                    $this->_createItem($this->_renderRangeLabel(empty($fromValue) ? 0 : $fromValue, $toValue), $filter)
                );
            }
        }

        return $this;
    }
public function apply ( \ Magento \ Framework \ App \ RequestInterface $ request ) { /**
         * Filter must be string: $fromPrice-$toPrice
         */ $ filter = $ request -> getParam ( $ this -> getRequestVar ( ) ) ; if ( $ filter && ! is_array ( $ filter ) ) { $ filterParams = explode ( ',' , $ filter ) ; $ filter = $ this -> dataProvider -> validateFilter ( $ filterParams [ 0 ] ) ; if ( $ filter ) { $ this -> dataProvider -> setInterval ( $ filter ) ; $ priorFilters = $ this -> dataProvider -> getPriorFilters ( $ filterParams ) ; if ( $ priorFilters ) { $ this -> dataProvider -> setPriorIntervals ( $ priorFilters ) ; } list ( $ fromValue , $ toValue ) = $ filter ; $ this -> setCurrentValue ( [ 'from' => $ fromValue , 'to' => $ toValue ] ) ; $ bounds = array_filter ( [ 'gte' => $ fromValue , 'lt' => $ toValue ] ) ; $ this -> getLayer ( ) -> getProductCollection ( ) -> addFieldToFilter ( $ this -> getAttributeModel ( ) -> getAttributeCode ( ) , $ this -> getRangeCondition ( $ bounds ) ) ; $ this -> getLayer ( ) -> getState ( ) -> addFilter ( $ this -> _createItem ( $ this -> _renderRangeLabel ( empty ( $ fromValue ) ? 0 : $ fromValue , $ toValue ) , $ filter ) ) ; } } return $ this ; }
Apply price range filter

@param \Magento\Framework\App\RequestInterface $request The request

@return $this
@throws \Magento\Framework\Exception\LocalizedException
Apply price range filter