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:
35: class Mage_Adminhtml_Block_Customer_Edit_Tab_Wishlist extends Mage_Adminhtml_Block_Widget_Grid
36: {
37: 38: 39: 40: 41:
42:
43: protected $_defaultSort = 'added_at';
44:
45: 46: 47: 48: 49:
50: protected $_parentTemplate;
51:
52: 53: 54:
55: protected $_productHelpers = array();
56:
57: 58: 59: 60:
61: public function __construct()
62: {
63: parent::__construct();
64: $this->setId('wishlistGrid');
65: $this->setUseAjax(true);
66: $this->_parentTemplate = $this->getTemplate();
67: $this->setTemplate('customer/tab/wishlist.phtml');
68: $this->setEmptyText(Mage::helper('customer')->__('No Items Found'));
69: $this->addProductConfigurationHelper('default', 'catalog/product_configuration');
70: }
71:
72: 73: 74: 75: 76:
77: protected function _getCustomer()
78: {
79: return Mage::registry('current_customer');
80: }
81:
82: 83: 84: 85: 86:
87: protected function _createCollection()
88: {
89: return Mage::getModel('wishlist/item')->getCollection();
90: }
91:
92: 93: 94: 95: 96:
97: protected function _prepareCollection()
98: {
99: $collection = $this->_createCollection()->addCustomerIdFilter($this->_getCustomer()->getId())
100: ->resetSortOrder()
101: ->addDaysInWishlist()
102: ->addStoreData();
103: $this->setCollection($collection);
104:
105: return parent::_prepareCollection();
106: }
107:
108: 109: 110: 111: 112:
113: protected function _prepareColumns()
114: {
115: $this->addColumn('product_name', array(
116: 'header' => Mage::helper('catalog')->__('Product name'),
117: 'index' => 'product_name',
118: 'renderer' => 'adminhtml/customer_edit_tab_view_grid_renderer_item'
119: ));
120:
121: $this->addColumn('description', array(
122: 'header' => Mage::helper('wishlist')->__('User description'),
123: 'index' => 'description',
124: 'renderer' => 'adminhtml/customer_edit_tab_wishlist_grid_renderer_description'
125: ));
126:
127: $this->addColumn('qty', array(
128: 'header' => Mage::helper('catalog')->__('Qty'),
129: 'index' => 'qty',
130: 'type' => 'number',
131: 'width' => '60px'
132: ));
133:
134: if (!Mage::app()->isSingleStoreMode()) {
135: $this->addColumn('store', array(
136: 'header' => Mage::helper('wishlist')->__('Added From'),
137: 'index' => 'store_id',
138: 'type' => 'store',
139: 'width' => '160px'
140: ));
141: }
142:
143: $this->addColumn('added_at', array(
144: 'header' => Mage::helper('wishlist')->__('Date Added'),
145: 'index' => 'added_at',
146: 'gmtoffset' => true,
147: 'type' => 'date'
148: ));
149:
150: $this->addColumn('days', array(
151: 'header' => Mage::helper('wishlist')->__('Days in Wishlist'),
152: 'index' => 'days_in_wishlist',
153: 'type' => 'number'
154: ));
155:
156: $this->addColumn('action', array(
157: 'header' => Mage::helper('customer')->__('Action'),
158: 'index' => 'wishlist_item_id',
159: 'renderer' => 'adminhtml/customer_grid_renderer_multiaction',
160: 'filter' => false,
161: 'sortable' => false,
162: 'actions' => array(
163: array(
164: 'caption' => Mage::helper('customer')->__('Configure'),
165: 'url' => 'javascript:void(0)',
166: 'process' => 'configurable',
167: 'control_object' => 'wishlistControl'
168: ),
169: array(
170: 'caption' => Mage::helper('customer')->__('Delete'),
171: 'url' => '#',
172: 'onclick' => 'return wishlistControl.removeItem($wishlist_item_id);'
173: )
174: )
175: ));
176:
177: return parent::_prepareColumns();
178: }
179:
180: 181: 182: 183: 184:
185: public function getGridUrl()
186: {
187: return $this->getUrl('*/*/wishlist', array('_current'=>true));
188: }
189:
190: 191: 192: 193: 194: 195:
196: protected function _addColumnFilterToCollection($column)
197: {
198:
199: $collection = $this->getCollection();
200: $value = $column->getFilter()->getValue();
201: if ($collection && $value) {
202: switch ($column->getId()) {
203: case 'product_name':
204: $collection->addProductNameFilter($value);
205: break;
206: case 'store':
207: $collection->addStoreFilter($value);
208: break;
209: case 'days':
210: $collection->addDaysFilter($value);
211: break;
212: default:
213: $collection->addFieldToFilter($column->getIndex(), $column->getFilter()->getCondition());
214: break;
215: }
216: }
217: return $this;
218: }
219:
220: 221: 222: 223: 224: 225:
226: protected function _setCollectionOrder($column)
227: {
228: $collection = $this->getCollection();
229: if ($collection) {
230: switch ($column->getId()) {
231: case 'product_name':
232: $collection->setOrderByProductName($column->getDir());
233: break;
234: default:
235: parent::_setCollectionOrder($column);
236: break;
237: }
238: }
239: return $this;
240: }
241:
242: 243: 244: 245: 246:
247: public function getGridParentHtml()
248: {
249: $templateName = Mage::getDesign()->getTemplateFilename($this->_parentTemplate, array('_relative'=>true));
250: return $this->fetchView($templateName);
251: }
252:
253: 254: 255: 256: 257:
258: public function getRowUrl($row)
259: {
260: return $this->getUrl('*/catalog_product/edit', array('id' => $row->getProductId()));
261: }
262:
263: 264: 265: 266: 267: 268: 269: 270:
271: public function addProductConfigurationHelper($productType, $helperName)
272: {
273: $this->_productHelpers[$productType] = $helperName;
274: return $this;
275: }
276:
277: 278: 279: 280: 281:
282: public function getProductConfigurationHelpers()
283: {
284: return $this->_productHelpers;
285: }
286: }
287: