1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Adminhtml dashboard totals bar
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Backend\Block\Dashboard;
class Totals extends \Magento\Backend\Block\Dashboard\Bar
{
/**
* @var string
*/
protected $_template = 'Magento_Backend::dashboard/totalbar.phtml';
/**
* @var \Magento\Framework\Module\Manager
*/
protected $_moduleManager;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
* @param \Magento\Framework\Module\Manager $moduleManager
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
\Magento\Framework\Module\Manager $moduleManager,
array $data = []
) {
$this->_moduleManager = $moduleManager;
parent::__construct($context, $collectionFactory, $data);
}
/**
* @return $this|void
*/
protected function _prepareLayout()
{
if (!$this->_moduleManager->isEnabled('Magento_Reports')) {
return $this;
}
$isFilter = $this->getRequest()->getParam(
'store'
) || $this->getRequest()->getParam(
'website'
) || $this->getRequest()->getParam(
'group'
);
$period = $this->getRequest()->getParam('period', '24h');
/* @var $collection \Magento\Reports\Model\ResourceModel\Order\Collection */
$collection = $this->_collectionFactory->create()->addCreateAtPeriodFilter(
$period
)->calculateTotals(
$isFilter
);
if ($this->getRequest()->getParam('store')) {
$collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
} else {
if ($this->getRequest()->getParam('website')) {
$storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
$collection->addFieldToFilter('store_id', ['in' => $storeIds]);
} else {
if ($this->getRequest()->getParam('group')) {
$storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
$collection->addFieldToFilter('store_id', ['in' => $storeIds]);
} elseif (!$collection->isLive()) {
$collection->addFieldToFilter(
'store_id',
['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
);
}
}
}
$collection->load();
$totals = $collection->getFirstItem();
$this->addTotal(__('Revenue'), $totals->getRevenue());
$this->addTotal(__('Tax'), $totals->getTax());
$this->addTotal(__('Shipping'), $totals->getShipping());
$this->addTotal(__('Quantity'), $totals->getQuantity() * 1, true);
}
}