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: class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('customerGrid');
41: $this->setUseAjax(true);
42: $this->setDefaultSort('entity_id');
43: $this->setSaveParametersInSession(true);
44: }
45:
46: protected function _prepareCollection()
47: {
48: $collection = Mage::getResourceModel('customer/customer_collection')
49: ->addNameToSelect()
50: ->addAttributeToSelect('email')
51: ->addAttributeToSelect('created_at')
52: ->addAttributeToSelect('group_id')
53: ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
54: ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
55: ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
56: ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
57: ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
58:
59: $this->setCollection($collection);
60:
61: return parent::_prepareCollection();
62: }
63:
64: protected function _prepareColumns()
65: {
66: $this->addColumn('entity_id', array(
67: 'header' => Mage::helper('customer')->__('ID'),
68: 'width' => '50px',
69: 'index' => 'entity_id',
70: 'type' => 'number',
71: ));
72: 73: 74: 75: 76: 77: 78: 79:
80: $this->addColumn('name', array(
81: 'header' => Mage::helper('customer')->__('Name'),
82: 'index' => 'name'
83: ));
84: $this->addColumn('email', array(
85: 'header' => Mage::helper('customer')->__('Email'),
86: 'width' => '150',
87: 'index' => 'email'
88: ));
89:
90: $groups = Mage::getResourceModel('customer/group_collection')
91: ->addFieldToFilter('customer_group_id', array('gt'=> 0))
92: ->load()
93: ->toOptionHash();
94:
95: $this->addColumn('group', array(
96: 'header' => Mage::helper('customer')->__('Group'),
97: 'width' => '100',
98: 'index' => 'group_id',
99: 'type' => 'options',
100: 'options' => $groups,
101: ));
102:
103: $this->addColumn('Telephone', array(
104: 'header' => Mage::helper('customer')->__('Telephone'),
105: 'width' => '100',
106: 'index' => 'billing_telephone'
107: ));
108:
109: $this->addColumn('billing_postcode', array(
110: 'header' => Mage::helper('customer')->__('ZIP'),
111: 'width' => '90',
112: 'index' => 'billing_postcode',
113: ));
114:
115: $this->addColumn('billing_country_id', array(
116: 'header' => Mage::helper('customer')->__('Country'),
117: 'width' => '100',
118: 'type' => 'country',
119: 'index' => 'billing_country_id',
120: ));
121:
122: $this->addColumn('billing_region', array(
123: 'header' => Mage::helper('customer')->__('State/Province'),
124: 'width' => '100',
125: 'index' => 'billing_region',
126: ));
127:
128: $this->addColumn('customer_since', array(
129: 'header' => Mage::helper('customer')->__('Customer Since'),
130: 'type' => 'datetime',
131: 'align' => 'center',
132: 'index' => 'created_at',
133: 'gmtoffset' => true
134: ));
135:
136: if (!Mage::app()->isSingleStoreMode()) {
137: $this->addColumn('website_id', array(
138: 'header' => Mage::helper('customer')->__('Website'),
139: 'align' => 'center',
140: 'width' => '80px',
141: 'type' => 'options',
142: 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
143: 'index' => 'website_id',
144: ));
145: }
146:
147: $this->addColumn('action',
148: array(
149: 'header' => Mage::helper('customer')->__('Action'),
150: 'width' => '100',
151: 'type' => 'action',
152: 'getter' => 'getId',
153: 'actions' => array(
154: array(
155: 'caption' => Mage::helper('customer')->__('Edit'),
156: 'url' => array('base'=> '*/*/edit'),
157: 'field' => 'id'
158: )
159: ),
160: 'filter' => false,
161: 'sortable' => false,
162: 'index' => 'stores',
163: 'is_system' => true,
164: ));
165:
166: $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
167: $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
168: return parent::_prepareColumns();
169: }
170:
171: protected function _prepareMassaction()
172: {
173: $this->setMassactionIdField('entity_id');
174: $this->getMassactionBlock()->setFormFieldName('customer');
175:
176: $this->getMassactionBlock()->addItem('delete', array(
177: 'label' => Mage::helper('customer')->__('Delete'),
178: 'url' => $this->getUrl('*/*/massDelete'),
179: 'confirm' => Mage::helper('customer')->__('Are you sure?')
180: ));
181:
182: $this->getMassactionBlock()->addItem('newsletter_subscribe', array(
183: 'label' => Mage::helper('customer')->__('Subscribe to Newsletter'),
184: 'url' => $this->getUrl('*/*/massSubscribe')
185: ));
186:
187: $this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
188: 'label' => Mage::helper('customer')->__('Unsubscribe from Newsletter'),
189: 'url' => $this->getUrl('*/*/massUnsubscribe')
190: ));
191:
192: $groups = $this->helper('customer')->getGroups()->toOptionArray();
193:
194: array_unshift($groups, array('label'=> '', 'value'=> ''));
195: $this->getMassactionBlock()->addItem('assign_group', array(
196: 'label' => Mage::helper('customer')->__('Assign a Customer Group'),
197: 'url' => $this->getUrl('*/*/massAssignGroup'),
198: 'additional' => array(
199: 'visibility' => array(
200: 'name' => 'group',
201: 'type' => 'select',
202: 'class' => 'required-entry',
203: 'label' => Mage::helper('customer')->__('Group'),
204: 'values' => $groups
205: )
206: )
207: ));
208:
209: return $this;
210: }
211:
212: public function getGridUrl()
213: {
214: return $this->getUrl('*/*/grid', array('_current'=> true));
215: }
216:
217: public function getRowUrl($row)
218: {
219: return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
220: }
221: }
222: