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_Report_ProductController extends Mage_Adminhtml_Controller_Report_Abstract
36: {
37: 38: 39: 40: 41:
42: public function _initAction()
43: {
44: parent::_initAction();
45: $this->_addBreadcrumb(Mage::helper('reports')->__('Products'), Mage::helper('reports')->__('Products'));
46: return $this;
47: }
48:
49: 50: 51: 52: 53:
54: public function orderedAction()
55: {
56: return $this->_forward('bestsellers', 'report_sales');
57: }
58:
59: 60: 61: 62: 63:
64: public function exportOrderedCsvAction()
65: {
66: return $this->_forward('exportBestsellersCsv', 'report_sales');
67: }
68:
69: 70: 71: 72: 73:
74: public function exportOrderedExcelAction()
75: {
76: return $this->_forward('exportBestsellersExcel', 'report_sales');
77: }
78:
79: 80: 81: 82:
83: public function soldAction()
84: {
85: $this->_title($this->__('Reports'))
86: ->_title($this->__('Products'))
87: ->_title($this->__('Products Ordered'));
88:
89: $this->_initAction()
90: ->_setActiveMenu('report/product/sold')
91: ->_addBreadcrumb(Mage::helper('reports')->__('Products Ordered'), Mage::helper('reports')->__('Products Ordered'))
92: ->_addContent($this->getLayout()->createBlock('adminhtml/report_product_sold'))
93: ->renderLayout();
94: }
95:
96: 97: 98: 99:
100: public function exportSoldCsvAction()
101: {
102: $fileName = 'products_ordered.csv';
103: $content = $this->getLayout()
104: ->createBlock('adminhtml/report_product_sold_grid')
105: ->getCsv();
106:
107: $this->_prepareDownloadResponse($fileName, $content);
108: }
109:
110: 111: 112: 113:
114: public function exportSoldExcelAction()
115: {
116: $fileName = 'products_ordered.xml';
117: $content = $this->getLayout()
118: ->createBlock('adminhtml/report_product_sold_grid')
119: ->getExcel($fileName);
120:
121: $this->_prepareDownloadResponse($fileName, $content);
122: }
123:
124: 125: 126: 127:
128: public function viewedAction()
129: {
130: $this->_title($this->__('Reports'))->_title($this->__('Products'))->_title($this->__('Most Viewed'));
131:
132: $this->_showLastExecutionTime(Mage_Reports_Model_Flag::REPORT_PRODUCT_VIEWED_FLAG_CODE, 'viewed');
133:
134: $this->_initAction()
135: ->_setActiveMenu('report/products/viewed')
136: ->_addBreadcrumb(Mage::helper('adminhtml')->__('Products Most Viewed Report'), Mage::helper('adminhtml')->__('Products Most Viewed Report'));
137:
138: $gridBlock = $this->getLayout()->getBlock('report_product_viewed.grid');
139: $filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');
140:
141: $this->_initReportAction(array(
142: $gridBlock,
143: $filterFormBlock
144: ));
145:
146: $this->renderLayout();
147: }
148:
149: 150: 151: 152:
153: public function exportViewedCsvAction()
154: {
155: $fileName = 'products_mostviewed.csv';
156: $grid = $this->getLayout()->createBlock('adminhtml/report_product_viewed_grid');
157: $this->_initReportAction($grid);
158: $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
159: }
160:
161: 162: 163: 164:
165: public function exportViewedExcelAction()
166: {
167: $fileName = 'products_mostviewed.xml';
168: $grid = $this->getLayout()->createBlock('adminhtml/report_product_viewed_grid');
169: $this->_initReportAction($grid);
170: $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
171: }
172:
173: 174: 175: 176:
177: public function lowstockAction()
178: {
179: $this->_title($this->__('Reports'))
180: ->_title($this->__('Products'))
181: ->_title($this->__('Low Stock'));
182:
183: $this->_initAction()
184: ->_setActiveMenu('report/product/lowstock')
185: ->_addBreadcrumb(Mage::helper('reports')->__('Low Stock'), Mage::helper('reports')->__('Low Stock'))
186: ->_addContent($this->getLayout()->createBlock('adminhtml/report_product_lowstock'))
187: ->renderLayout();
188: }
189:
190: 191: 192: 193:
194: public function exportLowstockCsvAction()
195: {
196: $fileName = 'products_lowstock.csv';
197: $content = $this->getLayout()->createBlock('adminhtml/report_product_lowstock_grid')
198: ->setSaveParametersInSession(true)
199: ->getCsv();
200:
201: $this->_prepareDownloadResponse($fileName, $content);
202: }
203:
204: 205: 206: 207:
208: public function exportLowstockExcelAction()
209: {
210: $fileName = 'products_lowstock.xml';
211: $content = $this->getLayout()->createBlock('adminhtml/report_product_lowstock_grid')
212: ->setSaveParametersInSession(true)
213: ->getExcel($fileName);
214:
215: $this->_prepareDownloadResponse($fileName, $content);
216: }
217:
218: 219: 220: 221:
222: public function downloadsAction()
223: {
224: $this->_title($this->__('Reports'))
225: ->_title($this->__('Products'))
226: ->_title($this->__('Downloads'));
227:
228: $this->_initAction()
229: ->_setActiveMenu('report/product/downloads')
230: ->_addBreadcrumb(Mage::helper('reports')->__('Downloads'), Mage::helper('reports')->__('Downloads'))
231: ->_addContent($this->getLayout()->createBlock('adminhtml/report_product_downloads'))
232: ->renderLayout();
233: }
234:
235: 236: 237: 238:
239: public function exportDownloadsCsvAction()
240: {
241: $fileName = 'products_downloads.csv';
242: $content = $this->getLayout()->createBlock('adminhtml/report_product_downloads_grid')
243: ->setSaveParametersInSession(true)
244: ->getCsv();
245:
246: $this->_prepareDownloadResponse($fileName, $content);
247: }
248:
249: 250: 251: 252:
253: public function exportDownloadsExcelAction()
254: {
255: $fileName = 'products_downloads.xml';
256: $content = $this->getLayout()->createBlock('adminhtml/report_product_downloads_grid')
257: ->setSaveParametersInSession(true)
258: ->getExcel($fileName);
259:
260: $this->_prepareDownloadResponse($fileName, $content);
261: }
262:
263: 264: 265: 266: 267:
268: protected function _isAllowed()
269: {
270: switch ($this->getRequest()->getActionName()) {
271: case 'viewed':
272: return Mage::getSingleton('admin/session')->isAllowed('report/products/viewed');
273: break;
274: case 'sold':
275: return Mage::getSingleton('admin/session')->isAllowed('report/products/sold');
276: break;
277: case 'lowstock':
278: return Mage::getSingleton('admin/session')->isAllowed('report/products/lowstock');
279: break;
280: default:
281: return Mage::getSingleton('admin/session')->isAllowed('report/products');
282: break;
283: }
284: }
285: }
286: