Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Totals.php
Go to the documentation of this file.
1 <?php
7 
13 {
21  protected function _countSum($index, $collection)
22  {
23  $sum = 0;
24  foreach ($collection as $item) {
25  if (!$item->hasChildren()) {
26  $sum += $item[$index];
27  } else {
28  $sum += $this->_countSum($index, $item->getChildren());
29  }
30  }
31  return $sum;
32  }
33 
41  protected function _countAverage($index, $collection)
42  {
43  $itemsCount = 0;
44  foreach ($collection as $item) {
45  if (!$item->hasChildren()) {
46  $itemsCount += 1;
47  } else {
48  $itemsCount += count($item->getChildren());
49  }
50  }
51 
52  return $itemsCount ? $this->_countSum($index, $collection) / $itemsCount : $itemsCount;
53  }
54 }
_countAverage($index, $collection)
Definition: Totals.php:41
_countSum($index, $collection)
Definition: Totals.php:21
$index
Definition: list.phtml:44