Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Price Class Reference

Public Member Functions

 __construct (Layer $layer, Registry $coreRegistry, ScopeConfigInterface $scopeConfig, \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price $resource)
 
 getInterval ()
 
 setInterval ($interval)
 
 getRangeCalculationValue ()
 
 getRangeStepValue ()
 
 getOnePriceIntervalValue ()
 
 getIntervalDivisionLimitValue ()
 
 getRangeMaxIntervalsValue ()
 
 getLayer ()
 
 getPriceRange ()
 
 getRangeItemCounts ($range)
 
 getMaxPrice ()
 
 getPriorFilters ($filterParams)
 
 validateFilter ($filter)
 
 getResetValue ()
 
 getPriorIntervals ()
 
 setPriorIntervals ($priorInterval)
 
 getResource ()
 
 getAdditionalRequestData ()
 

Data Fields

const XML_PATH_RANGE_CALCULATION = 'catalog/layered_navigation/price_range_calculation'
 
const XML_PATH_RANGE_STEP = 'catalog/layered_navigation/price_range_step'
 
const XML_PATH_RANGE_MAX_INTERVALS = 'catalog/layered_navigation/price_range_max_intervals'
 
const XML_PATH_ONE_PRICE_INTERVAL = 'catalog/layered_navigation/one_price_interval'
 
const XML_PATH_INTERVAL_DIVISION_LIMIT = 'catalog/layered_navigation/interval_division_limit'
 
const RANGE_CALCULATION_AUTO = 'auto'
 
const RANGE_CALCULATION_IMPROVED = 'improved'
 
const RANGE_CALCULATION_MANUAL = 'manual'
 
const MIN_RANGE_POWER = 10
 

Detailed Description

Definition at line 13 of file Price.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Layer  $layer,
Registry  $coreRegistry,
ScopeConfigInterface  $scopeConfig,
\Magento\Catalog\Model\ResourceModel\Layer\Filter\Price  $resource 
)
Parameters
Layer$layer
Registry$coreRegistry
ScopeConfigInterface$scopeConfig
\Magento\Catalog\Model\ResourceModel\Layer\Filter\Price$resource

Definition at line 93 of file Price.php.

98  {
99  $this->layer = $layer;
100  $this->coreRegistry = $coreRegistry;
101  $this->scopeConfig = $scopeConfig;
102  $this->resource = $resource;
103  }

Member Function Documentation

◆ getAdditionalRequestData()

getAdditionalRequestData ( )
Returns
string

Definition at line 369 of file Price.php.

370  {
371  $result = '';
372  $appliedInterval = $this->getInterval();
373  if ($appliedInterval) {
374  $result = ',' . $appliedInterval[0] . '-' . $appliedInterval[1];
375  $priorIntervals = $this->getResetValue();
376  if ($priorIntervals) {
377  $result .= ',' . $priorIntervals;
378  }
379  }
380 
381  return $result;
382  }

◆ getInterval()

getInterval ( )
Returns
array

Definition at line 108 of file Price.php.

109  {
110  return $this->interval;
111  }

◆ getIntervalDivisionLimitValue()

getIntervalDivisionLimitValue ( )

Get interval division limit

Returns
int

Definition at line 160 of file Price.php.

161  {
162  return $this->scopeConfig->getValue(
163  self::XML_PATH_INTERVAL_DIVISION_LIMIT,
164  ScopeInterface::SCOPE_STORE
165  );
166  }

◆ getLayer()

getLayer ( )
Returns
Layer

Definition at line 184 of file Price.php.

185  {
186  return $this->layer;
187  }

◆ getMaxPrice()

getMaxPrice ( )

Get maximum price from layer products set

Returns
float

Definition at line 264 of file Price.php.

265  {
266  $maxPrice = $this->maxPrice;
267  if ($maxPrice === null) {
268  $maxPrice = $this->getLayer()
269  ->getProductCollection()
270  ->getMaxPrice();
271  $maxPrice = floor($maxPrice);
272  $this->maxPrice = $maxPrice;
273  }
274 
275  return $maxPrice;
276  }

◆ getOnePriceIntervalValue()

getOnePriceIntervalValue ( )
Returns
mixed

Definition at line 147 of file Price.php.

148  {
149  return $this->scopeConfig->getValue(
150  self::XML_PATH_ONE_PRICE_INTERVAL,
151  ScopeInterface::SCOPE_STORE
152  );
153  }

◆ getPriceRange()

getPriceRange ( )

Get price range for building filter steps

Returns
int

Definition at line 194 of file Price.php.

195  {
196  $range = $this->priceRange;
197  if (!$range) {
198  $currentCategory = $this->coreRegistry->registry('current_category_filter');
199  if ($currentCategory) {
200  $range = $currentCategory->getFilterPriceRange();
201  } else {
202  $range = $this->getLayer()
203  ->getCurrentCategory()
204  ->getFilterPriceRange();
205  }
206 
207  if (!$range) {
208  $maxPrice = $this->getMaxPrice();
209  $calculation = $this->getRangeCalculationValue();
210  if ($calculation == self::RANGE_CALCULATION_AUTO) {
211  $index = 1;
212  do {
213  $range = pow(10, strlen(floor($maxPrice)) - $index);
214  $items = $this->getRangeItemCounts($range);
215  $index++;
216  } while ($range > self::MIN_RANGE_POWER && count($items) < 2);
217  } else {
218  $range = (double)$this->getRangeStepValue();
219  }
220  }
221 
222  $this->priceRange = $range;
223  }
224 
225  return $range;
226  }
$index
Definition: list.phtml:44
$items

◆ getPriorFilters()

getPriorFilters (   $filterParams)
Parameters
string$filterParams
Returns
array

Definition at line 282 of file Price.php.

283  {
284  $priorFilters = [];
285  $count = count($filterParams);
286  for ($i = 1; $i < $count; ++$i) {
287  $priorFilter = $this->validateFilter($filterParams[$i]);
288  if ($priorFilter) {
289  $priorFilters[] = $priorFilter;
290  } else {
291  //not valid data
292  $priorFilters = [];
293  break;
294  }
295  }
296 
297  return $priorFilters;
298  }
$count
Definition: recent.phtml:13
$i
Definition: gallery.phtml:31

◆ getPriorIntervals()

getPriorIntervals ( )
Returns
array

Definition at line 344 of file Price.php.

345  {
346  return $this->priorIntervals;
347  }

◆ getRangeCalculationValue()

getRangeCalculationValue ( )
Returns
mixed

Definition at line 125 of file Price.php.

126  {
127  return $this->scopeConfig->getValue(
128  self::XML_PATH_RANGE_CALCULATION,
129  ScopeInterface::SCOPE_STORE
130  );
131  }

◆ getRangeItemCounts()

getRangeItemCounts (   $range)

Get information about products count in range

Parameters
int$range
Returns
int

Definition at line 234 of file Price.php.

235  {
236  $items = array_key_exists($range, $this->rangeItemCounts) ? $this->rangeItemCounts[$range] : null;
237  if ($items === null) {
238  $items = $this->resource->getCount($range);
239  // checking max number of intervals
240  $i = 0;
241  $lastIndex = null;
242  $maxIntervalsNumber = $this->getRangeMaxIntervalsValue();
243  $calculation = $this->getRangeCalculationValue();
244  foreach ($items as $k => $v) {
245  ++$i;
246  if ($calculation == self::RANGE_CALCULATION_MANUAL && $i > 1 && $i > $maxIntervalsNumber) {
247  $items[$lastIndex] += $v;
248  unset($items[$k]);
249  } else {
250  $lastIndex = $k;
251  }
252  }
253  $this->rangeItemCounts[$range] = $items;
254  }
255 
256  return $items;
257  }
$i
Definition: gallery.phtml:31
$items

◆ getRangeMaxIntervalsValue()

getRangeMaxIntervalsValue ( )

Get maximum number of intervals

Returns
mixed

Definition at line 173 of file Price.php.

174  {
175  return $this->scopeConfig->getValue(
176  self::XML_PATH_RANGE_MAX_INTERVALS,
177  ScopeInterface::SCOPE_STORE
178  );
179  }

◆ getRangeStepValue()

getRangeStepValue ( )
Returns
mixed

Definition at line 136 of file Price.php.

137  {
138  return $this->scopeConfig->getValue(
139  self::XML_PATH_RANGE_STEP,
140  ScopeInterface::SCOPE_STORE
141  );
142  }

◆ getResetValue()

getResetValue ( )

Get filter value for reset current filter state

Returns
null|string

Definition at line 326 of file Price.php.

327  {
328  $priorIntervals = $this->getPriorIntervals();
329  $value = [];
330  if ($priorIntervals) {
331  foreach ($priorIntervals as $priorInterval) {
332  $value[] = implode('-', $priorInterval);
333  }
334 
335  return implode(',', $value);
336  }
337 
338  return null;
339  }
$value
Definition: gender.phtml:16

◆ getResource()

getResource ( )
Returns
\Magento\Catalog\Model\ResourceModel\Layer\Filter\Price

Definition at line 361 of file Price.php.

362  {
363  return $this->resource;
364  }

◆ setInterval()

setInterval (   $interval)
Parameters
array$interval
Returns
void

Definition at line 117 of file Price.php.

118  {
119  $this->interval = $interval;
120  }

◆ setPriorIntervals()

setPriorIntervals (   $priorInterval)
Parameters
array$priorInterval
Returns
void

Definition at line 353 of file Price.php.

354  {
355  $this->priorIntervals = $priorInterval;
356  }

◆ validateFilter()

validateFilter (   $filter)

Validate and parse filter request param

Parameters
string$filter
Returns
array|bool

Definition at line 306 of file Price.php.

307  {
308  $filter = explode('-', $filter);
309  if (count($filter) != 2) {
310  return false;
311  }
312  foreach ($filter as $v) {
313  if ($v !== '' && $v !== '0' && (double)$v <= 0 || is_infinite((double)$v)) {
314  return false;
315  }
316  }
317 
318  return $filter;
319  }

Field Documentation

◆ MIN_RANGE_POWER

const MIN_RANGE_POWER = 10

Minimal size of the range

Definition at line 40 of file Price.php.

◆ RANGE_CALCULATION_AUTO

const RANGE_CALCULATION_AUTO = 'auto'

Price layered navigation modes: Automatic (equalize price ranges), Automatic (equalize product counts), Manual

Definition at line 31 of file Price.php.

◆ RANGE_CALCULATION_IMPROVED

const RANGE_CALCULATION_IMPROVED = 'improved'

Definition at line 33 of file Price.php.

◆ RANGE_CALCULATION_MANUAL

const RANGE_CALCULATION_MANUAL = 'manual'

Definition at line 35 of file Price.php.

◆ XML_PATH_INTERVAL_DIVISION_LIMIT

const XML_PATH_INTERVAL_DIVISION_LIMIT = 'catalog/layered_navigation/interval_division_limit'

Definition at line 26 of file Price.php.

◆ XML_PATH_ONE_PRICE_INTERVAL

const XML_PATH_ONE_PRICE_INTERVAL = 'catalog/layered_navigation/one_price_interval'

Definition at line 24 of file Price.php.

◆ XML_PATH_RANGE_CALCULATION

const XML_PATH_RANGE_CALCULATION = 'catalog/layered_navigation/price_range_calculation'

XML configuration paths for Price Layered Navigation

Definition at line 18 of file Price.php.

◆ XML_PATH_RANGE_MAX_INTERVALS

const XML_PATH_RANGE_MAX_INTERVALS = 'catalog/layered_navigation/price_range_max_intervals'

Definition at line 22 of file Price.php.

◆ XML_PATH_RANGE_STEP

const XML_PATH_RANGE_STEP = 'catalog/layered_navigation/price_range_step'

Definition at line 20 of file Price.php.


The documentation for this class was generated from the following file: