1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34:
35: class Mage_Adminhtml_Block_Dashboard_Tab_Customers_Most extends Mage_Adminhtml_Block_Dashboard_Grid
36: {
37:
38: public function __construct()
39: {
40: parent::__construct();
41: $this->setId('customersMostGrid');
42: }
43:
44: protected function _prepareCollection()
45: {
46: $collection = Mage::getResourceModel('reports/order_collection');
47:
48: $collection
49: ->groupByCustomer()
50: ->addOrdersCount()
51: ->joinCustomerName();
52:
53: $storeFilter = 0;
54: if ($this->getParam('store')) {
55: $collection->addAttributeToFilter('store_id', $this->getParam('store'));
56: $storeFilter = 1;
57: } else if ($this->getParam('website')){
58: $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds();
59: $collection->addAttributeToFilter('store_id', array('in' => $storeIds));
60: } else if ($this->getParam('group')){
61: $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds();
62: $collection->addAttributeToFilter('store_id', array('in' => $storeIds));
63: }
64:
65: $collection->addSumAvgTotals($storeFilter)
66: ->orderByTotalAmount();
67:
68: $this->setCollection($collection);
69:
70: return parent::_prepareCollection();
71: }
72:
73: protected function _prepareColumns()
74: {
75: $this->addColumn('name', array(
76: 'header' => $this->__('Customer Name'),
77: 'sortable' => false,
78: 'index' => 'name'
79: ));
80:
81: $this->addColumn('orders_count', array(
82: 'header' => $this->__('Number of Orders'),
83: 'sortable' => false,
84: 'index' => 'orders_count',
85: 'type' => 'number'
86: ));
87:
88: $baseCurrencyCode = (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode();
89:
90: $this->addColumn('orders_avg_amount', array(
91: 'header' => $this->__('Average Order Amount'),
92: 'align' => 'right',
93: 'sortable' => false,
94: 'type' => 'currency',
95: 'currency_code' => $baseCurrencyCode,
96: 'index' => 'orders_avg_amount'
97: ));
98:
99: $this->addColumn('orders_sum_amount', array(
100: 'header' => $this->__('Total Order Amount'),
101: 'align' => 'right',
102: 'sortable' => false,
103: 'type' => 'currency',
104: 'currency_code' => $baseCurrencyCode,
105: 'index' => 'orders_sum_amount'
106: ));
107:
108: $this->setFilterVisibility(false);
109: $this->setPagerVisibility(false);
110:
111: return parent::_prepareColumns();
112: }
113:
114: public function getRowUrl($row)
115: {
116: return $this->getUrl('*/customer/edit', array('id'=>$row->getCustomerId()));
117: }
118: }
119: