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

addViewsCount() - how to apply function? 
 
eatyourbrain
Jr. Member
 
Total Posts:  3
Joined:  2009-04-13
 

hey folks,

i’ve been puzzling over this issue for 3 hours now without even a simple clue how to make use of this funcion’s result.

I’ve written a popularManufacturers cloud box, analysing the most viewn products, reading their manufacturers-attribute and building a cloud-list out of it, using this class to get the basic data:

<?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')
            ->
addAttributeToSelect('*')
            
//->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description', 'manufacturer', 'vinery'))
            
->setStoreId($storeId)
            ->
addStoreFilter($storeId)
            ->
addViewsCount();
            
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

        
//$products->setPageSize(6)->setCurPage(1);

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

the crucious line is supposed to be

->addViewsCount();

in order to calculate the ratios between different manufacturers’ products’ numbers of page views. But i’ve got no idea how to get down to the information this function “adds”.

This is the original code of the function in Mage_Reports_Model_Resource_Eav_Mysql4_Product_Collection:

public function addViewsCount($from ''$to '')
    
{
        
/**
         * Getting event type id for catalog_product_view event
         */
        
foreach (Mage::getModel('reports/event_type')->getCollection() as $eventType{
            
if ($eventType->getEventName() == 'catalog_product_view'{
                $productViewEvent 
$eventType->getId();
                break;
            
}
        }

        $this
->getSelect()->reset()
            ->
from(
                array(
'_table_views' => $this->getTable('reports/event')),
                array(
'views' => 'COUNT(_table_views.event_id)'))
            ->
join(array('e' => $this->getProductEntityTableName()),
                
"e.entity_id = _table_views.object_id AND e.entity_type_id = {$this->getProductEntityTypeId()}")
            ->
where('_table_views.event_type_id = ?'$productViewEvent)
            ->
group('e.entity_id')
            ->
order('views desc')
            ->
having('views > 0');

        if (
$from != '' && $to != ''{
            $this
->getSelect()
                ->
where('logged_at >= ?'$from)
                ->
where('logged_at <= ?'$to);
        
}

        
return $this;
    
}

but, shame on me for that, neither do i understand how it works nor how to make use of it. I didnt count but I guess that I’ve been saying the word “fu*k” like 30 times or so to myself over the past hour.

Anybody knows how to save my night?

Cheers and thanks a lot,

jaejae

 
Magento Community Magento Community
Magento Community
Magento Community
 
eatyourbrain
Jr. Member
 
Total Posts:  3
Joined:  2009-04-13
 

sweet, I’m officially a dumbass now… I just tried:

<?php echo $_product->getData('views'?>

in the template block and felt something similar to having sex.

For all the people out there with no girlfriend, here’s the solution xD

jaejae

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