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_Viewed extends Mage_Adminhtml_Block_Dashboard_Grid
36: {
37:
38: public function __construct()
39: {
40: parent::__construct();
41: $this->setId('productsReviewedGrid');
42: }
43:
44: protected function _prepareCollection()
45: {
46: if ($this->getParam('website')) {
47: $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds();
48: $storeId = array_pop($storeIds);
49: } else if ($this->getParam('group')) {
50: $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds();
51: $storeId = array_pop($storeIds);
52: } else {
53: $storeId = (int)$this->getParam('store');
54: }
55: $collection = Mage::getResourceModel('reports/product_collection')
56: ->addAttributeToSelect('*')
57: ->addViewsCount()
58: ->setStoreId($storeId)
59: ->addStoreFilter($storeId);
60:
61: $this->setCollection($collection);
62:
63: return parent::_prepareCollection();
64: }
65:
66: protected function _prepareColumns()
67: {
68: $this->addColumn('name', array(
69: 'header' =>Mage::helper('reports')->__('Product Name'),
70: 'sortable' => false,
71: 'index' =>'name'
72: ));
73:
74: $this->addColumn('price', array(
75: 'header' =>Mage::helper('reports')->__('Price'),
76: 'width' =>'120px',
77: 'type' =>'currency',
78: 'currency_code' => (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode(),
79: 'sortable' => false,
80: 'index' =>'price'
81: ));
82:
83: $this->addColumn('views', array(
84: 'header' =>Mage::helper('reports')->__('Number of Views'),
85: 'width' =>'120px',
86: 'align' =>'right',
87: 'sortable' => false,
88: 'index' =>'views'
89: ));
90:
91: $this->setFilterVisibility(false);
92: $this->setPagerVisibility(false);
93:
94: return parent::_prepareColumns();
95: }
96:
97: public function getRowUrl($row)
98: {
99: $params = array('id'=>$row->getId());
100: if ($this->getRequest()->getParam('store')) {
101: $params['store'] = $this->getRequest()->getParam('store');
102: }
103: return $this->getUrl('*/catalog_product/edit', $params);
104: }
105: }
106: