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_Edit_Tab_Tag extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('tag_grid');
41: $this->setDefaultSort('name');
42: $this->setDefaultDir('ASC');
43: $this->setUseAjax(true);
44: $this->setFilterVisibility(false);
45: }
46:
47: protected function _prepareCollection()
48: {
49: $tagId = Mage::registry('tagId');
50:
51: if( $this->getCustomerId() instanceof Mage_Customer_Model_Customer ) {
52: $this->setCustomerId( $this->getCustomerId()->getId() );
53: }
54:
55: $collection = Mage::getResourceModel('tag/customer_collection')
56: ->addCustomerFilter($this->getCustomerId())
57: ->addGroupByTag();
58:
59: $this->setCollection($collection);
60: return parent::_prepareCollection();
61: }
62:
63: protected function _afterLoadCollection()
64: {
65: $this->getCollection()->addProductName();
66: return parent::_afterLoadCollection();
67: }
68:
69: protected function _prepareColumns()
70: {
71: $this->addColumn('name', array(
72: 'header' => Mage::helper('customer')->__('Tag Name'),
73: 'index' => 'name',
74: ));
75:
76: $this->addColumn('status', array(
77: 'header' => Mage::helper('customer')->__('Status'),
78: 'width' => '90px',
79: 'index' => 'status',
80: 'type' => 'options',
81: 'options' => array(
82: Mage_Tag_Model_Tag::STATUS_DISABLED => Mage::helper('customer')->__('Disabled'),
83: Mage_Tag_Model_Tag::STATUS_PENDING => Mage::helper('customer')->__('Pending'),
84: Mage_Tag_Model_Tag::STATUS_APPROVED => Mage::helper('customer')->__('Approved'),
85: ),
86: 'filter' => false,
87: ));
88:
89: $this->addColumn('product', array(
90: 'header' => Mage::helper('customer')->__('Product Name'),
91: 'index' => 'product',
92: 'filter' => false,
93: 'sortable' => false,
94: ));
95:
96: $this->addColumn('product_sku', array(
97: 'header' => Mage::helper('customer')->__('SKU'),
98: 'index' => 'product_sku',
99: 'filter' => false,
100: 'sortable' => false,
101: ));
102:
103: return parent::_prepareColumns();
104: }
105:
106: public function getRowUrl($row)
107: {
108: return $this->getUrl('*/tag/edit', array(
109: 'tag_id' => $row->getTagId(),
110: 'customer_id' => $this->getCustomerId(),
111: ));
112: }
113:
114: public function getGridUrl()
115: {
116: return $this->getUrl('*/customer/tagGrid', array(
117: '_current' => true,
118: 'id' => $this->getCustomerId()
119: ));
120: }
121:
122: }
123: