Ejemplo n.º 1
0
 /**
  * Apply price range filter
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return $this
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function apply(\Magento\Framework\App\RequestInterface $request)
 {
     /**
      * Filter must be string: $fromPrice-$toPrice
      */
     $filter = $request->getParam($this->getRequestVar());
     if (!$filter || is_array($filter)) {
         return $this;
     }
     $filterParams = explode(',', $filter);
     $filter = $this->dataProvider->validateFilter($filterParams[0]);
     if (!$filter) {
         return $this;
     }
     $this->dataProvider->setInterval($filter);
     $priorFilters = $this->dataProvider->getPriorFilters($filterParams);
     if ($priorFilters) {
         $this->dataProvider->setPriorIntervals($priorFilters);
     }
     list($from, $to) = $filter;
     $this->getLayer()->getProductCollection()->addFieldToFilter('price', ['from' => $from, 'to' => empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA]);
     $this->getLayer()->getState()->addFilter($this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter));
     return $this;
 }
Ejemplo n.º 2
0
 public function testInterval()
 {
     $interval = 100500;
     $this->target->setInterval($interval);
     $this->assertSame($interval, $this->target->getInterval());
 }