Tuesday, 15 September 2015

Magento Category Product Listing Sort by Most Viewed Product


You Just want to orverride app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php

paste in code\local\Mage\Catalog\Block\Product\List\Toolbar.php


first add your most viewed in sort by product select box

 public function getAvailableOrders()


       $this->addOrderToAvailableOrders('mostviewd', 'MOST POPULAR');

        return $this->_availableOrder;\\you can add this code here

 public function setCollection($collection)


if ($this->getCurrentOrder()) {

               if($this->getCurrentOrder()=='mostviewd') {
joinInner('report_event AS _table_views',
' _table_views.object_id = e.entity_id',
'COUNT(_table_views.event_id) AS views')->
group('e.entity_id')->order('views DESC');



add this code and check the result.

1 comment:

Thank You For Comment