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_Tag_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('tag_customer_grid' . Mage::registry('current_tag')->getId());
41: $this->setDefaultSort('name');
42: $this->setDefaultDir('ASC');
43: $this->setUseAjax(true);
44: }
45: 46: 47: 48: 49:
50: public function getGridUrl()
51: {
52: return $this->getUrl('*/*/customer', array('_current' => true));
53: }
54:
55: protected function _prepareCollection()
56: {
57: $tagId = Mage::registry('current_tag')->getId();
58: $storeId = Mage::registry('current_tag')->getStoreId();
59: $collection = Mage::getModel('tag/tag')
60: ->getCustomerCollection()
61: ->addTagFilter($tagId)
62: ->setCountAttribute('tr.tag_relation_id')
63: ->addStoreFilter($storeId)
64: ->addGroupByCustomerProduct();
65:
66: $this->setCollection($collection);
67: return parent::_prepareCollection();
68: }
69:
70: protected function _afterLoadCollection()
71: {
72: $this->getCollection()->addProductName();
73: return parent::_afterLoadCollection();
74: }
75:
76: protected function _prepareColumns()
77: {
78: $this->addColumn('customer_id', array(
79: 'header' => Mage::helper('tag')->__('ID'),
80: 'width' => 50,
81: 'align' => 'right',
82: 'index' => 'entity_id',
83: ));
84:
85: $this->addColumn('firstname', array(
86: 'header' => Mage::helper('tag')->__('First Name'),
87: 'index' => 'firstname',
88: ));
89:
90: $this->addColumn('lastname', array(
91: 'header' => Mage::helper('tag')->__('Last Name'),
92: 'index' => 'lastname',
93: ));
94:
95: $this->addColumn('product', array(
96: 'header' => Mage::helper('tag')->__('Product Name'),
97: 'filter' => false,
98: 'sortable' => false,
99: 'index' => 'product',
100: ));
101:
102: $this->addColumn('product_sku', array(
103: 'header' => Mage::helper('tag')->__('Product SKU'),
104: 'filter' => false,
105: 'sortable' => false,
106: 'width' => 50,
107: 'align' => 'right',
108: 'index' => 'product_sku',
109: ));
110:
111:
112:
113: return parent::_prepareColumns();
114: }
115:
116: public function getRowUrl($row)
117: {
118: return $this->getUrl('*/customer/edit', array('id' => $row->getId()));
119: }
120:
121: }
122: