/**
  * Prepare price filter model
  *
  * @param \Magento\TestFramework\Request|null $request
  */
 protected function _prepareFilter($request = null)
 {
     /** @var $layer \Magento\Catalog\Model\Layer */
     $layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Category');
     $layer->setCurrentCategory(4);
     $layer->setState(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\State'));
     /** @var $filter \Magento\Catalog\Model\Layer\Filter\Price */
     $filter = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Filter\\Price', array('layer' => $layer));
     $filter->setLayer($layer)->setAttributeModel(new \Magento\Framework\Object(array('attribute_code' => 'price')));
     if (!is_null($request)) {
         $filter->apply($request, \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Framework\\View\\Element\\Text'));
         $interval = $filter->getInterval();
         if ($interval) {
             $this->_model->setLimits($interval[0], $interval[1]);
         }
     }
     $collection = $layer->getProductCollection();
     $this->_model->setPricesModel($filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize());
 }
Exemple #2
0
 /**
  * Get data generated by algorithm for build price filter items
  *
  * @return array
  */
 protected function _getCalculatedItemsData()
 {
     $collection = $this->getLayer()->getProductCollection();
     $appliedInterval = $this->getInterval();
     if ($appliedInterval && $collection->getPricesCount() <= $this->getIntervalDivisionLimit()) {
         return array();
     }
     $this->_priceAlgorithm->setPricesModel($this)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getPricesCount());
     if ($appliedInterval) {
         if ($appliedInterval[0] == $appliedInterval[1] || $appliedInterval[1] === '0') {
             return array();
         }
         $this->_priceAlgorithm->setLimits($appliedInterval[0], $appliedInterval[1]);
     }
     $items = array();
     foreach ($this->_priceAlgorithm->calculateSeparators() as $separator) {
         $items[] = array('label' => $this->_renderRangeLabel($separator['from'], $separator['to']), 'value' => ($separator['from'] == 0 ? '' : $separator['from']) . '-' . $separator['to'] . $this->_getAdditionalRequestData(), 'count' => $separator['count']);
     }
     return $items;
 }