Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Most.php
Go to the documentation of this file.
1 <?php
7 
15 class Most extends \Magento\Backend\Block\Dashboard\Grid
16 {
21 
28  public function __construct(
29  \Magento\Backend\Block\Template\Context $context,
30  \Magento\Backend\Helper\Data $backendHelper,
31  \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
32  array $data = []
33  ) {
34  $this->_collectionFactory = $collectionFactory;
35  parent::__construct($context, $backendHelper, $data);
36  }
37 
41  protected function _construct()
42  {
43  parent::_construct();
44  $this->setId('customersMostGrid');
45  }
46 
50  protected function _prepareCollection()
51  {
52  $collection = $this->_collectionFactory->create();
53  /* @var $collection \Magento\Reports\Model\ResourceModel\Order\Collection */
54  $collection->groupByCustomer()->addOrdersCount()->joinCustomerName();
55 
56  $storeFilter = 0;
57  if ($this->getParam('store')) {
58  $collection->addAttributeToFilter('store_id', $this->getParam('store'));
59  $storeFilter = 1;
60  } elseif ($this->getParam('website')) {
61  $storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds();
62  $collection->addAttributeToFilter('store_id', ['in' => $storeIds]);
63  } elseif ($this->getParam('group')) {
64  $storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds();
65  $collection->addAttributeToFilter('store_id', ['in' => $storeIds]);
66  }
67 
68  $collection->addSumAvgTotals($storeFilter)->orderByTotalAmount();
69 
70  $this->setCollection($collection);
71 
72  return parent::_prepareCollection();
73  }
74 
78  protected function _prepareColumns()
79  {
80  $this->addColumn('name', ['header' => __('Customer'), 'sortable' => false, 'index' => 'name']);
81 
82  $this->addColumn(
83  'orders_count',
84  [
85  'header' => __('Orders'),
86  'sortable' => false,
87  'index' => 'orders_count',
88  'type' => 'number',
89  'header_css_class' => 'col-orders',
90  'column_css_class' => 'col-orders'
91  ]
92  );
93 
94  $baseCurrencyCode = (string)$this->_storeManager->getStore(
95  (int)$this->getParam('store')
96  )->getBaseCurrencyCode();
97 
98  $this->addColumn(
99  'orders_avg_amount',
100  [
101  'header' => __('Average'),
102  'sortable' => false,
103  'type' => 'currency',
104  'currency_code' => $baseCurrencyCode,
105  'index' => 'orders_avg_amount',
106  'header_css_class' => 'col-avg',
107  'column_css_class' => 'col-avg'
108  ]
109  );
110 
111  $this->addColumn(
112  'orders_sum_amount',
113  [
114  'header' => __('Total'),
115  'sortable' => false,
116  'type' => 'currency',
117  'currency_code' => $baseCurrencyCode,
118  'index' => 'orders_sum_amount',
119  'header_css_class' => 'col-total',
120  'column_css_class' => 'col-total'
121  ]
122  );
123 
124  $this->setFilterVisibility(false);
125  $this->setPagerVisibility(false);
126 
127  return parent::_prepareColumns();
128  }
129 
133  public function getRowUrl($row)
134  {
135  return $this->getUrl('customer/index/edit', ['id' => $row->getCustomerId()]);
136  }
137 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
setPagerVisibility($visible=true)
Definition: Grid.php:588
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory, array $data=[])
Definition: Most.php:28
getParam($paramName, $default=null)
Definition: Grid.php:729