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_Dashboard_Tab_Products_Ordered extends Mage_Adminhtml_Block_Dashboard_Grid
36: {
37:
38: public function __construct()
39: {
40: parent::__construct();
41: $this->setId('productsOrderedGrid');
42: }
43:
44: protected function _prepareCollection()
45: {
46: if (!Mage::helper('core')->isModuleEnabled('Mage_Sales')) {
47: return $this;
48: }
49: if ($this->getParam('website')) {
50: $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds();
51: $storeId = array_pop($storeIds);
52: } else if ($this->getParam('group')) {
53: $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds();
54: $storeId = array_pop($storeIds);
55: } else {
56: $storeId = (int)$this->getParam('store');
57: }
58:
59: $collection = Mage::getResourceModel('sales/report_bestsellers_collection')
60: ->setModel('catalog/product')
61: ->addStoreFilter($storeId)
62: ;
63:
64: $this->setCollection($collection);
65:
66: return parent::_prepareCollection();
67: }
68:
69: protected function _prepareColumns()
70: {
71:
72: $this->addColumn('name', array(
73: 'header' => Mage::helper('sales')->__('Product Name'),
74: 'sortable' => false,
75: 'index' => 'product_name'
76: ));
77:
78: $this->addColumn('price', array(
79: 'header' => Mage::helper('sales')->__('Price'),
80: 'width' => '120px',
81: 'type' => 'currency',
82: 'currency_code' => (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode(),
83: 'sortable' => false,
84: 'index' => 'product_price'
85: ));
86:
87: $this->addColumn('ordered_qty', array(
88: 'header' => Mage::helper('sales')->__('Quantity Ordered'),
89: 'width' => '120px',
90: 'align' => 'right',
91: 'sortable' => false,
92: 'index' => 'qty_ordered',
93: 'type' => 'number'
94: ));
95:
96: $this->setFilterVisibility(false);
97: $this->setPagerVisibility(false);
98:
99: return parent::_prepareColumns();
100: }
101:
102: 103: 104: 105: 106: 107: 108: 109:
110: public function getRowUrl($row)
111: {
112:
113: $productId = $row->getProductId();
114:
115:
116: if (!$productId) {
117: return '';
118: }
119:
120: $params = array('id' => $productId);
121: if ($this->getRequest()->getParam('store')) {
122: $params['store'] = $this->getRequest()->getParam('store');
123: }
124: return $this->getUrl('*/catalog_product/edit', $params);
125: }
126: }
127: