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_Report_Product_Lowstock_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36:
37:
38: public function __construct()
39: {
40: parent::__construct();
41: $this->setId('gridLowstock');
42: $this->setUseAjax(false);
43: }
44:
45: protected function _prepareCollection()
46: {
47: if ($this->getRequest()->getParam('website')) {
48: $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
49: $storeId = array_pop($storeIds);
50: } else if ($this->getRequest()->getParam('group')) {
51: $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
52: $storeId = array_pop($storeIds);
53: } else if ($this->getRequest()->getParam('store')) {
54: $storeId = (int)$this->getRequest()->getParam('store');
55: } else {
56: $storeId = '';
57: }
58:
59:
60: $collection = Mage::getResourceModel('reports/product_lowstock_collection')
61: ->addAttributeToSelect('*')
62: ->setStoreId($storeId)
63: ->filterByIsQtyProductTypes()
64: ->joinInventoryItem('qty')
65: ->useManageStockFilter($storeId)
66: ->useNotifyStockQtyFilter($storeId)
67: ->setOrder('qty', Varien_Data_Collection::SORT_ORDER_ASC);
68:
69: if( $storeId ) {
70: $collection->addStoreFilter($storeId);
71: }
72:
73: $this->setCollection($collection);
74: return parent::_prepareCollection();
75: }
76:
77: protected function _prepareColumns()
78: {
79: $this->addColumn('name', array(
80: 'header' =>Mage::helper('reports')->__('Product Name'),
81: 'sortable' =>false,
82: 'index' =>'name'
83: ));
84:
85: $this->addColumn('sku', array(
86: 'header' =>Mage::helper('reports')->__('Product SKU'),
87: 'sortable' =>false,
88: 'index' =>'sku'
89: ));
90:
91: $this->addColumn('qty', array(
92: 'header' =>Mage::helper('reports')->__('Stock Qty'),
93: 'width' =>'215px',
94: 'align' =>'right',
95: 'sortable' =>false,
96: 'filter' =>'adminhtml/widget_grid_column_filter_range',
97: 'index' =>'qty',
98: 'type' =>'number'
99: ));
100:
101: $this->addExportType('*/*/exportLowstockCsv', Mage::helper('reports')->__('CSV'));
102: $this->addExportType('*/*/exportLowstockExcel', Mage::helper('reports')->__('Excel XML'));
103:
104: return parent::_prepareColumns();
105: }
106: }
107: