Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Newest.php
Go to the documentation of this file.
1 <?php
7 
15 class Newest 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\Customer\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('customersNewestGrid');
45  }
46 
50  protected function _prepareCollection()
51  {
52  $collection = $this->_collectionFactory->create()->addCustomerName();
53 
54  $storeFilter = 0;
55  if ($this->getParam('store')) {
56  $collection->addAttributeToFilter('store_id', $this->getParam('store'));
57  $storeFilter = 1;
58  } elseif ($this->getParam('website')) {
59  $storeIds = $this->_storeManager->getWebsite($this->getParam('website'))->getStoreIds();
60  $collection->addAttributeToFilter('store_id', ['in' => $storeIds]);
61  } elseif ($this->getParam('group')) {
62  $storeIds = $this->_storeManager->getGroup($this->getParam('group'))->getStoreIds();
63  $collection->addAttributeToFilter('store_id', ['in' => $storeIds]);
64  }
65 
66  $collection->addOrdersStatistics($storeFilter)->orderByCustomerRegistration();
67 
68  $this->setCollection($collection);
69 
70  return parent::_prepareCollection();
71  }
72 
76  protected function _prepareColumns()
77  {
78  $this->addColumn('name', ['header' => __('Customer'), 'sortable' => false, 'index' => 'name']);
79 
80  $this->addColumn(
81  'orders_count',
82  [
83  'header' => __('Orders'),
84  'sortable' => false,
85  'index' => 'orders_count',
86  'type' => 'number',
87  'header_css_class' => 'col-orders',
88  'column_css_class' => 'col-orders'
89  ]
90  );
91 
92  $baseCurrencyCode = (string)$this->_storeManager->getStore(
93  (int)$this->getParam('store')
94  )->getBaseCurrencyCode();
95 
96  $this->addColumn(
97  'orders_avg_amount',
98  [
99  'header' => __('Average'),
100  'sortable' => false,
101  'type' => 'currency',
102  'currency_code' => $baseCurrencyCode,
103  'index' => 'orders_avg_amount',
104  'renderer' => \Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency::class,
105  'header_css_class' => 'col-avg',
106  'column_css_class' => 'col-avg'
107  ]
108  );
109 
110  $this->addColumn(
111  'orders_sum_amount',
112  [
113  'header' => __('Total'),
114  'sortable' => false,
115  'type' => 'currency',
116  'currency_code' => $baseCurrencyCode,
117  'index' => 'orders_sum_amount',
118  'renderer' => \Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency::class,
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->getId()]);
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\Customer\CollectionFactory $collectionFactory, array $data=[])
Definition: Newest.php:28
getParam($paramName, $default=null)
Definition: Grid.php:729