00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Block_Report_Product_Lowstock_Grid extends Mage_Adminhtml_Block_Widget_Grid
00035 {
00036
00037
00038 public function __construct()
00039 {
00040 parent::__construct();
00041 $this->setId('gridLowstock');
00042 $this->setUseAjax(false);
00043 }
00044
00045 protected function _prepareCollection()
00046 {
00047 if ($this->getRequest()->getParam('website')) {
00048 $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
00049 $storeId = array_pop($storeIds);
00050 } else if ($this->getRequest()->getParam('group')) {
00051 $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
00052 $storeId = array_pop($storeIds);
00053 } else if ($this->getRequest()->getParam('store')) {
00054 $storeId = (int)$this->getRequest()->getParam('store');
00055 } else {
00056 $storeId = '';
00057 }
00058
00059 $collection = Mage::getModel('catalog/product')->getCollection()
00060 ->addAttributeToSelect('*')
00061 ->setStoreId($storeId)
00062 ->addAttributeToFilter('type_id', array(
00063 Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
00064 Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL
00065 ))
00066 ->joinField('qty',
00067 'cataloginventory/stock_item',
00068 'qty',
00069 'product_id=entity_id',
00070 '{{table}}.stock_id=1',
00071 'left')
00072 ->setOrder('qty', 'asc');
00073
00074 if( $storeId ) {
00075 $collection->addStoreFilter($storeId);
00076 }
00077
00078 $this->setCollection($collection);
00079 return parent::_prepareCollection();
00080 }
00081
00082 protected function _prepareColumns()
00083 {
00084 $this->addColumn('name', array(
00085 'header' =>Mage::helper('reports')->__('Product Name'),
00086 'sortable' =>false,
00087 'index' =>'name'
00088 ));
00089
00090 $this->addColumn('sku', array(
00091 'header' =>Mage::helper('reports')->__('Product Sku'),
00092 'sortable' =>false,
00093 'index' =>'sku'
00094 ));
00095
00096 $this->addColumn('qty', array(
00097 'header' =>Mage::helper('reports')->__('Stock Qty'),
00098 'width' =>'215px',
00099 'align' =>'right',
00100 'sortable' =>false,
00101 'filter' =>'adminhtml/widget_grid_column_filter_range',
00102 'index' =>'qty',
00103 'type' =>'number'
00104 ));
00105
00106 $this->addExportType('*/*/exportLowstockCsv', Mage::helper('reports')->__('CSV'));
00107 $this->addExportType('*/*/exportLowstockExcel', Mage::helper('reports')->__('Excel'));
00108
00109 return parent::_prepareColumns();
00110 }
00111 }