Newest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Dashboard\Tab\Customers;
  7. /**
  8. * Adminhtml dashboard most recent customers grid
  9. *
  10. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Newest extends \Magento\Backend\Block\Dashboard\Grid
  15. {
  16. /**
  17. * @var \Magento\Reports\Model\ResourceModel\Customer\CollectionFactory
  18. */
  19. protected $_collectionFactory;
  20. /**
  21. * @param \Magento\Backend\Block\Template\Context $context
  22. * @param \Magento\Backend\Helper\Data $backendHelper
  23. * @param \Magento\Reports\Model\ResourceModel\Customer\CollectionFactory $collectionFactory
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Backend\Block\Template\Context $context,
  28. \Magento\Backend\Helper\Data $backendHelper,
  29. \Magento\Reports\Model\ResourceModel\Customer\CollectionFactory $collectionFactory,
  30. array $data = []
  31. ) {
  32. $this->_collectionFactory = $collectionFactory;
  33. parent::__construct($context, $backendHelper, $data);
  34. }
  35. /**
  36. * @return void
  37. */
  38. protected function _construct()
  39. {
  40. parent::_construct();
  41. $this->setId('customersNewestGrid');
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. protected function _prepareCollection()
  47. {
  48. $collection = $this->_collectionFactory->create()->addCustomerName();
  49. $storeFilter = 0;
  50. if ($this->getParam('store')) {
  51. $collection->addAttributeToFilter('store_id', $this->getParam('store'));
  52. $storeFilter = 1;
  53. } elseif ($this->getParam('website')) {
  54. $storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds();
  55. $collection->addAttributeToFilter('store_id', ['in' => $storeIds]);
  56. } elseif ($this->getParam('group')) {
  57. $storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds();
  58. $collection->addAttributeToFilter('store_id', ['in' => $storeIds]);
  59. }
  60. $collection->addOrdersStatistics($storeFilter)->orderByCustomerRegistration();
  61. $this->setCollection($collection);
  62. return parent::_prepareCollection();
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. protected function _prepareColumns()
  68. {
  69. $this->addColumn('name', ['header' => __('Customer'), 'sortable' => false, 'index' => 'name']);
  70. $this->addColumn(
  71. 'orders_count',
  72. [
  73. 'header' => __('Orders'),
  74. 'sortable' => false,
  75. 'index' => 'orders_count',
  76. 'type' => 'number',
  77. 'header_css_class' => 'col-orders',
  78. 'column_css_class' => 'col-orders'
  79. ]
  80. );
  81. $baseCurrencyCode = (string)$this->_storeManager->getStore(
  82. (int)$this->getParam('store')
  83. )->getBaseCurrencyCode();
  84. $this->addColumn(
  85. 'orders_avg_amount',
  86. [
  87. 'header' => __('Average'),
  88. 'sortable' => false,
  89. 'type' => 'currency',
  90. 'currency_code' => $baseCurrencyCode,
  91. 'index' => 'orders_avg_amount',
  92. 'renderer' => \Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency::class,
  93. 'header_css_class' => 'col-avg',
  94. 'column_css_class' => 'col-avg'
  95. ]
  96. );
  97. $this->addColumn(
  98. 'orders_sum_amount',
  99. [
  100. 'header' => __('Total'),
  101. 'sortable' => false,
  102. 'type' => 'currency',
  103. 'currency_code' => $baseCurrencyCode,
  104. 'index' => 'orders_sum_amount',
  105. 'renderer' => \Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency::class,
  106. 'header_css_class' => 'col-total',
  107. 'column_css_class' => 'col-total'
  108. ]
  109. );
  110. $this->setFilterVisibility(false);
  111. $this->setPagerVisibility(false);
  112. return parent::_prepareColumns();
  113. }
  114. /**
  115. * {@inheritdoc}
  116. */
  117. public function getRowUrl($row)
  118. {
  119. return $this->getUrl('customer/index/edit', ['id' => $row->getId()]);
  120. }
  121. }