Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Collection.php
Go to the documentation of this file.
1 <?php
13 
14 class Collection extends \Magento\Sales\Model\ResourceModel\Report\Collection\AbstractCollection
15 {
19  protected $_periodFormat;
20 
26  protected $_aggregationTable = 'tax_order_aggregated_created';
27 
31  protected $_selectedColumns = [];
32 
41  public function __construct(
42  \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
43  \Psr\Log\LoggerInterface $logger,
44  \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
45  \Magento\Framework\Event\ManagerInterface $eventManager,
46  \Magento\Sales\Model\ResourceModel\Report $resource,
47  \Magento\Framework\DB\Adapter\AdapterInterface $connection = null
48  ) {
49  $resource->init($this->_aggregationTable);
50  parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $resource, $connection);
51  }
52 
56  protected function _getSelectedColumns()
57  {
58  if ('month' == $this->_period) {
59  $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y-%m');
60  } elseif ('year' == $this->_period) {
61  $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y');
62  } else {
63  $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y-%m-%d');
64  }
65 
66  if (!$this->isTotals() && !$this->isSubTotals()) {
67  $this->_selectedColumns = [
68  'period' => $this->_periodFormat,
69  'code' => 'code',
70  'percent' => 'percent',
71  'orders_count' => 'SUM(orders_count)',
72  'tax_base_amount_sum' => 'SUM(tax_base_amount_sum)',
73  ];
74  }
75 
76  if ($this->isTotals()) {
77  $this->_selectedColumns = $this->getAggregatedColumns();
78  }
79 
80  if ($this->isSubTotals()) {
81  $this->_selectedColumns = $this->getAggregatedColumns() + ['period' => $this->_periodFormat];
82  }
83 
85  }
86 
92  protected function _beforeLoad()
93  {
94  $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns());
95  if (!$this->isTotals() && !$this->isSubTotals()) {
96  $this->getSelect()->group([$this->_periodFormat, 'code', 'percent']);
97  }
98 
99  if ($this->isSubTotals()) {
100  $this->getSelect()->group([$this->_periodFormat]);
101  }
102  return parent::_beforeLoad();
103  }
104 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Sales\Model\ResourceModel\Report $resource, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)
Definition: Collection.php:41
$resource
Definition: bulk.php:12
$logger
$connection
Definition: bulk.php:13