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_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37: public function __construct()
38: {
39: parent::__construct();
40: $this->setId('tag_product_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:
51: public function getGridUrl()
52: {
53: return $this->getUrl('*/*/product', array('_current' => true));
54: }
55:
56: protected function _prepareCollection()
57: {
58: $tagId = Mage::registry('current_tag')->getId();
59: $storeId = Mage::registry('current_tag')->getStoreId();
60: $collection = Mage::getModel('tag/tag')
61: ->getEntityCollection()
62: ->addTagFilter($tagId)
63: ->addCustomerFilter(array('null' => false))
64: ->addStoreFilter($storeId)
65: ->addPopularity($tagId);
66:
67: $this->setCollection($collection);
68: return parent::_prepareCollection();
69: }
70:
71: protected function _afterLoadCollection()
72: {
73: return parent::_afterLoadCollection();
74: }
75:
76: protected function _prepareColumns()
77: {
78: $this->addColumn('product_id', array(
79: 'header' => Mage::helper('tag')->__('ID'),
80: 'width' => '50px',
81: 'align' => 'right',
82: 'index' => 'entity_id',
83: ));
84:
85: $this->addColumn('name', array(
86: 'header' => Mage::helper('tag')->__('Product Name'),
87: 'index' => 'name',
88: ));
89:
90: $this->addColumn('popularity', array(
91: 'header' => Mage::helper('tag')->__('# of Uses'),
92: 'width' => '50px',
93: 'align' => 'right',
94: 'index' => 'popularity',
95: 'type' => 'number'
96: ));
97:
98: $this->addColumn('sku', array(
99: 'header' => Mage::helper('tag')->__('SKU'),
100: 'filter' => false,
101: 'sortable' => false,
102: 'width' => 50,
103: 'align' => 'right',
104: 'index' => 'sku',
105: ));
106:
107: return parent::_prepareColumns();
108: }
109:
110: protected function _addColumnFilterToCollection($column)
111: {
112: if($column->getIndex() == 'popularity') {
113: $this->getCollection()->addPopularityFilter($column->getFilter()->getCondition());
114: return $this;
115: } else {
116: return parent::_addColumnFilterToCollection($column);
117: }
118: }
119:
120: public function getRowUrl($row)
121: {
122: return $this->getUrl('*/catalog_product/edit', array('id' => $row->getProductId()));
123: }
124:
125: }
126: