Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Order.php
Go to the documentation of this file.
1 <?php
7 
13 class Order extends \Magento\Sales\Model\ResourceModel\Report\Collection\AbstractCollection
14 {
20  protected $_periodFormat;
21 
27  protected $_selectedColumns = [];
28 
37  public function __construct(
38  \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
39  \Psr\Log\LoggerInterface $logger,
40  \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
41  \Magento\Framework\Event\ManagerInterface $eventManager,
43  \Magento\Framework\DB\Adapter\AdapterInterface $connection = null
44  ) {
45  $resource->init('sales_shipping_aggregated_order');
46  parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $resource, $connection);
47  }
48 
54  protected function _getSelectedColumns()
55  {
56  $connection = $this->getConnection();
57  if ('month' == $this->_period) {
58  $this->_periodFormat = $connection->getDateFormatSql('period', '%Y-%m');
59  } elseif ('year' == $this->_period) {
60  $this->_periodFormat = $connection->getDateExtractSql(
61  'period',
62  \Magento\Framework\DB\Adapter\AdapterInterface::INTERVAL_YEAR
63  );
64  } else {
65  $this->_periodFormat = $connection->getDateFormatSql('period', '%Y-%m-%d');
66  }
67 
68  if (!$this->isTotals() && !$this->isSubTotals()) {
69  $this->_selectedColumns = [
70  'period' => $this->_periodFormat,
71  'shipping_description' => 'shipping_description',
72  'orders_count' => 'SUM(orders_count)',
73  'total_shipping' => 'SUM(total_shipping)',
74  'total_shipping_actual' => 'SUM(total_shipping_actual)',
75  ];
76  }
77 
78  if ($this->isTotals()) {
79  $this->_selectedColumns = $this->getAggregatedColumns();
80  }
81 
82  if ($this->isSubTotals()) {
83  $this->_selectedColumns = $this->getAggregatedColumns() + ['period' => $this->_periodFormat];
84  }
85 
87  }
88 
94  protected function _beforeLoad()
95  {
96  $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns());
97 
98  if (!$this->isTotals() && !$this->isSubTotals()) {
99  $this->getSelect()->group([$this->_periodFormat, 'shipping_description']);
100  }
101  if ($this->isSubTotals()) {
102  $this->getSelect()->group([$this->_periodFormat]);
103  }
104  return parent::_beforeLoad();
105  }
106 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$resource
Definition: bulk.php:12
$logger
__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: Order.php:37
$connection
Definition: bulk.php:13