Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getItemsData(array $intervals = [], $additionalRequestData = '')
 {
     $collection = $this->layer->getProductCollection();
     $appliedInterval = $intervals;
     if ($appliedInterval && $collection->getPricesCount() <= $this->getIntervalDivisionLimit()) {
         return [];
     }
     $this->algorithm->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getPricesCount());
     if ($appliedInterval) {
         if ($appliedInterval[0] == $appliedInterval[1] || $appliedInterval[1] === '0') {
             return [];
         }
         $this->algorithm->setLimits($appliedInterval[0], $appliedInterval[1]);
     }
     $interval = $this->intervalFactory->create();
     $items = [];
     foreach ($this->algorithm->calculateSeparators($interval) as $separator) {
         $items[] = ['label' => $this->render->renderRangeLabel($separator['from'], $separator['to']), 'value' => ($separator['from'] == 0 ? '' : $separator['from']) . '-' . $separator['to'] . $additionalRequestData, 'count' => $separator['count']];
     }
     return $items;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getItems(BucketInterface $bucket, array $dimensions, \Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
 {
     $aggregations = $this->dataProvider->getAggregations($entityStorage);
     $options = $this->options->get();
     if ($aggregations['count'] < $options['interval_division_limit']) {
         return [];
     }
     $this->algorithm->setStatistics($aggregations['min'], $aggregations['max'], $aggregations['std'], $aggregations['count']);
     $this->algorithm->setLimits($aggregations['min'], $aggregations['max'] + 0.01);
     $interval = $this->dataProvider->getInterval($bucket, $dimensions, $entityStorage);
     $data = $this->algorithm->calculateSeparators($interval);
     $data[0]['from'] = '';
     // We should not calculate min and max value
     $data[count($data) - 1]['to'] = '';
     $dataSize = count($data);
     for ($key = 0; $key < $dataSize; $key++) {
         if (isset($data[$key + 1])) {
             $data[$key]['to'] = $data[$key + 1]['from'];
         }
     }
     return $data;
 }