app/code/local/Mage/Catalog/Block/Product/Mostviewed.php
class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract{
public function __construct(){
parent::__construct();
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->addAttributeToSelect(array('name', 'price', 'small_image'))
->setStoreId($storeId)
->addStoreFilter($storeId)
->addViewsCount();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$products->setPageSize(5)->setCurPage(1);
$this->setProductCollection($products);
}
}
[Step 2] Create a mostviewed.phtml file and put it here :
app/design/frontend/*/*/template/catalog/product/mostviewed.phtml
getProductCollection()) && $_products->getSize()): ?>__('These Products Are Popular Right Now!') ?>getItems()); echo $_collectionSize; ?>getItems() as $_product): ?>
- >
htmlEscape($_product->getName()) ?>
getRatingSummary()): ?>
getReviewsSummaryHtml($_product, 'short') ?>
getPriceHtml($_product, true) ?>
isSaleable()): ?>
__('Out of stock') ?>
helper('wishlist')->isAllow()) : ?>
- __('Add to Wishlist') ?>
getAddToCompareUrl($_product)): ?>- | __('Add to Compare') ?>
[Step 3] now put this line where you want to view mostviewed products..
{{block type="catalog/product_mostviewed" template="catalog/product/mostviewed.phtml"}}
Source : http://harisur.net/how-to-get-mostviewed-products-in-magento
No comments:
Post a Comment