Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Most Viewed Products db
 
sandrzejuk
Jr. Member
 
Total Posts:  18
Joined:  2012-03-19
 

Does anyone know which data base holds the Most Viewed Products details which are available on the dashboard?
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
stevejcoates
Member
 
Avatar
Total Posts:  54
Joined:  2011-08-24
Poole, Dorset
 

Hi sandrzejuk,

Not entirely sure where in the DB but if you wanted to show the ‘Most Viewed’ products on your site try this:

Put this file in /app/code/local/Mage/Catalog/Block/Product

Mostviewed.php

<?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')) //edit to suit tastes
            
->setStoreId($storeId)
            ->
addStoreFilter($storeId)
            ->
addViewsCount();


        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

        
$products->setPageSize(3)->setCurPage(1);

        
$this->setProductCollection($products);
    
}
}

Then place this file here /app/design/frontend/<your_theme>/template/catalog/product

mostviewed.phtml

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<?php mainBlock
('top'?>
    
<div class="page-title">
        
<?php title('top'?>
            
<h2><?php echo $this->__('Most Viewed'?></h2>
        
<?php title('bottom'?> 
    
</div>
<?php $_collectionSize count($_products->getItems()) ?>
<table class="products-grid" id="products-grid-table">
<?php $i=1; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i%1!==0): ?>
    
<tr>
    
<?php endif ?>
        
<td id="td_<?php echo $i;?>" <?php if($i%3==or $i==$_collectionSize){echo 'class="last"';} ?> >
            
<?php contentBlock('top'?>
    
<div id="cont_<?php echo $i;?>">
        <
h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
        <
class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
            <
img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(122, 109); ?>" width="122" height="109" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
        </
a>
        <
div class="a-center">                        
        
<?php if($_product->getRatingSummary()): ?>
                <?php 
echo $this->getReviewsSummaryHtml($_product'short'?>
            <?php 
endif; ?>
                        <?php 
echo $this->getPriceHtml($_producttrue?>
                            <?php 
if($_product->isSaleable()): ?>
                            
<button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><span><?php echo $this->__('Add to Cart'?></span></span></span></button>
                            <
div class="clear"></div>
                
<?php else: ?>
                            
<class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock'?></span></p>
                            <
div class="clear"></div>
                            
<?php endif; ?>
            
<ul class="add-to-links">
                
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('Add to Wishlist'?></a></li>
                
<?php endif; ?>
                <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                
<li class="last"><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare'?></a></li>
                
<?php endif; ?>
            
</ul>

        </
div>
    </
div>
    
<?php contentBlock('bottom'?>
    
</td>
    
<?php if ($i%3==or $i==$_collectionSize): ?>
   
</tr>
    
<?php endif ?>
  <?php $i
++; endforeach; $kol $_collectionSize?>
</table>
    <
script type="text/javascript">decorateTable('products-grid-table');
        function 
setHeight(items){for (1<= itemsi++ ){document.getElementById('cont_'+i).style.height document.getElementById('td_'+i).offsetHeight-40+'px';}}                
        setTimeout
('setHeight(<?php echo $kol ?>)'1000);
    
</script>
<?php mainBlock
('bottom'?>
<?php 
endif; ?>

Then place this snippet in any of your CMS pages that you want the most viewed products to appear:

{{block type="catalog/product_mostviewed" template="catalog/product/mostviewed.phtml"}}

Hope that helps. If you need further support get in touch!

-Steve (www.beetleweb.com)

 
Magento Community Magento Community
Magento Community
Magento Community
 
sandrzejuk
Jr. Member
 
Total Posts:  18
Joined:  2012-03-19
 

Hi Steve
Thanks for this. It will definitely be usefull in a bit. However what I need to do is purge that db, so that I can reset the dashboard stats. I’ve looked a bit on here and can’t find any thread that would help.

Seb

 
Magento Community Magento Community
Magento Community
Magento Community
 
sandrzejuk
Jr. Member
 
Total Posts:  18
Joined:  2012-03-19
 
sandrzejuk - 21 June 2012 10:42 AM

Hi Steve
Thanks for this. It will definitely be usefull in a bit. However what I need to do is purge that db, so that I can reset the dashboard stats. I’ve looked a bit on here and can’t find any thread that would help.

Seb

Sorted. Cleared the report_viewed_product_index db. You also have to clear the yearly, monthly etc.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tangodeal
Jr. Member
 
Total Posts:  2
Joined:  2011-07-17
 

it is giving me this error

Fatal error: Call to undefined function mainBlock() in /home/tangodea/public_html/app/design/frontend/default/lightshop_green/template/catalog/product/mostviewed.phtml on line 2

 
Magento Community Magento Community
Magento Community
Magento Community
 
GianniCasa
Jr. Member
 
Total Posts:  16
Joined:  2009-10-28
 

Same error, any idea?

 
Magento Community Magento Community
Magento Community
Magento Community
 
dfeg
Jr. Member
 
Total Posts:  1
Joined:  2012-07-21
 

Im was having the same error and found the solution here
http://www.magentocommerce.com/boards/viewthread/14764/P30/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top