Totals.php 3.2 KB

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