PageRenderTime 129ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php

https://github.com/speedupmate/Magento-CE-Mirror
PHP | 221 lines | 157 code | 25 blank | 39 comment | 1 complexity | acd01d8a416cce308db88fff18f90584 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Adminhtml customer grid block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
  34. {
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. $this->setId('customerGrid');
  39. $this->setUseAjax(true);
  40. $this->setDefaultSort('entity_id');
  41. $this->setSaveParametersInSession(true);
  42. }
  43. protected function _prepareCollection()
  44. {
  45. $collection = Mage::getResourceModel('customer/customer_collection')
  46. ->addNameToSelect()
  47. ->addAttributeToSelect('email')
  48. ->addAttributeToSelect('created_at')
  49. ->addAttributeToSelect('group_id')
  50. ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
  51. ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
  52. ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
  53. ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
  54. ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
  55. $this->setCollection($collection);
  56. return parent::_prepareCollection();
  57. }
  58. protected function _prepareColumns()
  59. {
  60. $this->addColumn('entity_id', array(
  61. 'header' => Mage::helper('customer')->__('ID'),
  62. 'width' => '50px',
  63. 'index' => 'entity_id',
  64. 'type' => 'number',
  65. ));
  66. /*$this->addColumn('firstname', array(
  67. 'header' => Mage::helper('customer')->__('First Name'),
  68. 'index' => 'firstname'
  69. ));
  70. $this->addColumn('lastname', array(
  71. 'header' => Mage::helper('customer')->__('Last Name'),
  72. 'index' => 'lastname'
  73. ));*/
  74. $this->addColumn('name', array(
  75. 'header' => Mage::helper('customer')->__('Name'),
  76. 'index' => 'name'
  77. ));
  78. $this->addColumn('email', array(
  79. 'header' => Mage::helper('customer')->__('Email'),
  80. 'width' => '150',
  81. 'index' => 'email'
  82. ));
  83. $groups = Mage::getResourceModel('customer/group_collection')
  84. ->addFieldToFilter('customer_group_id', array('gt'=> 0))
  85. ->load()
  86. ->toOptionHash();
  87. $this->addColumn('group', array(
  88. 'header' => Mage::helper('customer')->__('Group'),
  89. 'width' => '100',
  90. 'index' => 'group_id',
  91. 'type' => 'options',
  92. 'options' => $groups,
  93. ));
  94. $this->addColumn('Telephone', array(
  95. 'header' => Mage::helper('customer')->__('Telephone'),
  96. 'width' => '100',
  97. 'index' => 'billing_telephone'
  98. ));
  99. $this->addColumn('billing_postcode', array(
  100. 'header' => Mage::helper('customer')->__('ZIP'),
  101. 'width' => '90',
  102. 'index' => 'billing_postcode',
  103. ));
  104. $this->addColumn('billing_country_id', array(
  105. 'header' => Mage::helper('customer')->__('Country'),
  106. 'width' => '100',
  107. 'type' => 'country',
  108. 'index' => 'billing_country_id',
  109. ));
  110. $this->addColumn('billing_region', array(
  111. 'header' => Mage::helper('customer')->__('State/Province'),
  112. 'width' => '100',
  113. 'index' => 'billing_region',
  114. ));
  115. $this->addColumn('customer_since', array(
  116. 'header' => Mage::helper('customer')->__('Customer Since'),
  117. 'type' => 'datetime',
  118. 'align' => 'center',
  119. 'index' => 'created_at',
  120. 'gmtoffset' => true
  121. ));
  122. if (!Mage::app()->isSingleStoreMode()) {
  123. $this->addColumn('website_id', array(
  124. 'header' => Mage::helper('customer')->__('Website'),
  125. 'align' => 'center',
  126. 'width' => '80px',
  127. 'type' => 'options',
  128. 'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
  129. 'index' => 'website_id',
  130. ));
  131. }
  132. $this->addColumn('action',
  133. array(
  134. 'header' => Mage::helper('customer')->__('Action'),
  135. 'width' => '100',
  136. 'type' => 'action',
  137. 'getter' => 'getId',
  138. 'actions' => array(
  139. array(
  140. 'caption' => Mage::helper('customer')->__('Edit'),
  141. 'url' => array('base'=> '*/*/edit'),
  142. 'field' => 'id'
  143. )
  144. ),
  145. 'filter' => false,
  146. 'sortable' => false,
  147. 'index' => 'stores',
  148. 'is_system' => true,
  149. ));
  150. $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
  151. $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
  152. return parent::_prepareColumns();
  153. }
  154. protected function _prepareMassaction()
  155. {
  156. $this->setMassactionIdField('entity_id');
  157. $this->getMassactionBlock()->setFormFieldName('customer');
  158. $this->getMassactionBlock()->addItem('delete', array(
  159. 'label' => Mage::helper('customer')->__('Delete'),
  160. 'url' => $this->getUrl('*/*/massDelete'),
  161. 'confirm' => Mage::helper('customer')->__('Are you sure?')
  162. ));
  163. $this->getMassactionBlock()->addItem('newsletter_subscribe', array(
  164. 'label' => Mage::helper('customer')->__('Subscribe to Newsletter'),
  165. 'url' => $this->getUrl('*/*/massSubscribe')
  166. ));
  167. $this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
  168. 'label' => Mage::helper('customer')->__('Unsubscribe from Newsletter'),
  169. 'url' => $this->getUrl('*/*/massUnsubscribe')
  170. ));
  171. $groups = $this->helper('customer')->getGroups()->toOptionArray();
  172. array_unshift($groups, array('label'=> '', 'value'=> ''));
  173. $this->getMassactionBlock()->addItem('assign_group', array(
  174. 'label' => Mage::helper('customer')->__('Assign a Customer Group'),
  175. 'url' => $this->getUrl('*/*/massAssignGroup'),
  176. 'additional' => array(
  177. 'visibility' => array(
  178. 'name' => 'group',
  179. 'type' => 'select',
  180. 'class' => 'required-entry',
  181. 'label' => Mage::helper('customer')->__('Group'),
  182. 'values' => $groups
  183. )
  184. )
  185. ));
  186. return $this;
  187. }
  188. public function getGridUrl()
  189. {
  190. return $this->getUrl('*/*/grid', array('_current'=> true));
  191. }
  192. public function getRowUrl($row)
  193. {
  194. return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
  195. }
  196. }