Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Sales.php
Go to the documentation of this file.
1 <?php
7 
13 class Sales extends \Magento\Backend\Block\Dashboard\Bar
14 {
18  protected $_template = 'Magento_Backend::dashboard/salebar.phtml';
19 
23  protected $_moduleManager;
24 
31  public function __construct(
32  \Magento\Backend\Block\Template\Context $context,
33  \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
34  \Magento\Framework\Module\Manager $moduleManager,
35  array $data = []
36  ) {
37  $this->_moduleManager = $moduleManager;
38  parent::__construct($context, $collectionFactory, $data);
39  }
40 
44  protected function _prepareLayout()
45  {
46  if (!$this->_moduleManager->isEnabled('Magento_Reports')) {
47  return $this;
48  }
49  $isFilter = $this->getRequest()->getParam(
50  'store'
51  ) || $this->getRequest()->getParam(
52  'website'
53  ) || $this->getRequest()->getParam(
54  'group'
55  );
56 
57  $collection = $this->_collectionFactory->create()->calculateSales($isFilter);
58 
59  if ($this->getRequest()->getParam('store')) {
60  $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
61  } elseif ($this->getRequest()->getParam('website')) {
62  $storeIds = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
63  $collection->addFieldToFilter('store_id', ['in' => $storeIds]);
64  } elseif ($this->getRequest()->getParam('group')) {
65  $storeIds = $this->_storeManager->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
66  $collection->addFieldToFilter('store_id', ['in' => $storeIds]);
67  }
68 
69  $collection->load();
70  $sales = $collection->getFirstItem();
71 
72  $this->addTotal(__('Lifetime Sales'), $sales->getLifetime());
73  $this->addTotal(__('Average Order'), $sales->getAverage());
74  }
75 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$moduleManager
Definition: products.php:75
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory, \Magento\Framework\Module\Manager $moduleManager, array $data=[])
Definition: Sales.php:31
addTotal($label, $value, $isQuantity=false)
Definition: Bar.php:39