Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Manual.php
Go to the documentation of this file.
1 <?php
7 
16 
17 class Manual implements AlgorithmInterface
18 {
19  const XML_PATH_RANGE_MAX_INTERVALS = 'catalog/layered_navigation/price_range_max_intervals';
20 
30  public function __construct(
31  Algorithm $algorithm,
32  Resolver $layerResolver,
33  ScopeConfigInterface $scopeConfig,
34  Render $render,
35  Registry $coreRegistry,
37  Range $range
38  ) {
39  $this->algorithm = $algorithm;
40  $this->layer = $layerResolver->get();
41  $this->scopeConfig = $scopeConfig;
42  $this->render = $render;
43  $this->coreRegistry = $coreRegistry;
44  $this->range = $range;
45  $this->resource = $resource;
46  }
47 
54  public function getItemsData(array $intervals = [], $additionalRequestData = '')
55  {
56  $data = [];
57  if (empty($intervals)) {
58  $range = $this->range->getPriceRange();
59  if (!$range) {
60  $range = $this->range->getConfigRangeStep();
61  $dbRanges = $this->resource->getCount($range);
62  $dbRanges = $this->processRange($dbRanges);
63  $data = $this->render->renderRangeData($range, $dbRanges);
64  }
65  }
66 
67  return $data;
68  }
69 
74  private function processRange($items)
75  {
76  $i = 0;
77  $lastIndex = null;
78  $maxIntervalsNumber = $this->getMaxIntervalsNumber();
79  foreach ($items as $k => $v) {
80  ++$i;
81  if ($i > 1 && $i > $maxIntervalsNumber) {
82  $items[$lastIndex] += $v;
83  unset($items[$k]);
84  } else {
85  $lastIndex = $k;
86  }
87  }
88  return $items;
89  }
90 
96  public function getMaxIntervalsNumber()
97  {
98  return (int)$this->scopeConfig->getValue(
99  self::XML_PATH_RANGE_MAX_INTERVALS,
100  ScopeInterface::SCOPE_STORE
101  );
102  }
103 }
__construct(Algorithm $algorithm, Resolver $layerResolver, ScopeConfigInterface $scopeConfig, Render $render, Registry $coreRegistry, Price $resource, Range $range)
Definition: Manual.php:30
getItemsData(array $intervals=[], $additionalRequestData='')
Definition: Manual.php:54
$resource
Definition: bulk.php:12
$i
Definition: gallery.phtml:31
$items