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
00035 class Mage_Adminhtml_Block_Dashboard_Tab_Products_Ordered extends Mage_Adminhtml_Block_Dashboard_Grid
00036 {
00037
00038 public function __construct()
00039 {
00040 parent::__construct();
00041 $this->setId('productsOrderedGrid');
00042 }
00043
00044 protected function _prepareCollection()
00045 {
00046 if ($this->getParam('website')) {
00047 $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds();
00048 $storeId = array_pop($storeIds);
00049 } else if ($this->getParam('group')) {
00050 $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds();
00051 $storeId = array_pop($storeIds);
00052 } else {
00053 $storeId = (int)$this->getParam('store');
00054 }
00055
00056 $collection = Mage::getResourceModel('reports/product_collection')
00057 ->addOrderedQty()
00058 ->addAttributeToSelect(array('name', 'price'))
00059 ->setStoreId($storeId)
00060 ->addStoreFilter($storeId)
00061 ->setOrder('ordered_qty', 'desc');
00062
00063 $this->setCollection($collection);
00064
00065 return parent::_prepareCollection();
00066 }
00067
00068 protected function _prepareColumns()
00069 {
00070
00071 $this->addColumn('name', array(
00072 'header' =>Mage::helper('reports')->__('Product Name'),
00073 'sortable' => false,
00074 'index' =>'name'
00075 ));
00076
00077 $this->addColumn('price', array(
00078 'header' =>Mage::helper('reports')->__('Price'),
00079 'width' =>'120px',
00080 'type' =>'currency',
00081 'currency_code' => (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode(),
00082 'sortable' => false,
00083 'index' =>'price'
00084 ));
00085
00086 $this->addColumn('ordered_qty', array(
00087 'header' =>Mage::helper('reports')->__('Quantity Ordered'),
00088 'width' =>'120px',
00089 'align' =>'right',
00090 'sortable' => false,
00091 'index' =>'ordered_qty',
00092 'type' =>'number'
00093 ));
00094
00095 $this->setFilterVisibility(false);
00096 $this->setPagerVisibility(false);
00097
00098 return parent::_prepareColumns();
00099 }
00100
00101 public function getRowUrl($row)
00102 {
00103 $params = array('id'=>$row->getId());
00104 if ($this->getRequest()->getParam('store')) {
00105 $params['store'] = $this->getRequest()->getParam('store');
00106 }
00107 return $this->getUrl('*/catalog_product/edit', $params);
00108 }
00109 }