sorting - About mostviewed sort by in magento 1.7.0.2 -
product mostviewed file located here:
app/code/local/mage/catalog/block/product/mostviewed.php
i have added following code:
class mage_catalog_block_product_mostviewed extends mage_catalog_block_product_abstract { public function __construct(){ parent::__construct(); $storeid = mage::app()->getstore()->getid(); $collection = mage::getresourcemodel('reports/product_collection')->addviewscount(); $collection->getselect()->joininner(array('e2' => 'catalog_product_flat_'.$storeid), 'e2.entity_id = e.entity_id'); $collection->addattributetoselect('*'); //$collection->printlogquery(true); //exit(); $this->setproductcollection($collection); } protected function _preparelayout() { parent::_preparelayout(); $toolbar = $this->getlayout()->createblock('catalog/product_list_toolbar', microtime()) ->setcollection($this->getproductcollection()); $pager = $this->getlayout()->createblock('page/html_pager', microtime()); $toolbar->setchild('product_list_toolbar_pager', $pager); $this->setchild('toolbar', $toolbar); $this->getproductcollection()->load(); return $this; } public function getpagerhtml() { return $this->getchildhtml('toolbar'); } }
not added addviewscount()
print sql:
select `e`.*, `e2`.* `catalog_product_entity` `e` inner join `catalog_product_flat_1` `e2` on e2.entity_id = e.entity_id
added addviewscount()
print sql:
select count(report_table_views.event_id) `views`, `e`.*, `e2`.* `report_event` `report_table_views` inner join `catalog_product_entity` `e` on e.entity_id = report_table_views.object_id , e.entity_type_id = 4 inner join `catalog_product_flat_1` `e2` on e2.entity_id = e.entity_id (report_table_views.event_type_id = 1) group `e`.`entity_id` having (count(report_table_views.event_id) > 0) order `views` desc
added addviewscount()
sort not working,working in delete addviewscount()
.
how fix it?
edited: problem solved.there wrong mysql db.the code no problem.thank @liyakat @alex.
you can view count through mage_reports_model_resource_product_collection model.
// set $to
, $from
empty string disable time range filtering
$storeid = mage::app()->getstore()->getid(); $products = mage::getresourcemodel('reports/product_collection') ->addattributetoselect('*') ->setstoreid($storeid) ->addstorefilter($storeid) ->addviewscount() ->joinfield('inventory_in_stock', 'cataloginventory/stock_item', 'is_in_stock', 'product_id=entity_id', '{{table}}.is_in_stock=1'); mage::getsingleton('catalog/product_status') ->addvisiblefiltertocollection($products); mage::getsingleton('catalog/product_visibility') ->addvisibleincatalogfiltertocollection($products); $products->getselect()->limit( 15 ); return $products;
please let me know if can more
Comments
Post a Comment