0

I have the following code inside my footer.phtml file:

<?php echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>

This should output the the recently viewed products inside my footer. This works if a customer is logged in but when anyone visits the site nothing gets shown?

This code only seems to have changed in this way since CE 1.9.0 upgrade (previously ok on 1.8.1). Is there a way of making it show for everyone?

1 Answer 1

1

Not an answer as such but a few pointers as to where and what to look for.

Firstly the block that you are looking into is Mage_Reports_Block_Product_Viewed. In this block you will see the function _toHtml and in this function you will see that it checks to see if there are items in the cache and if not then it will load them from the database.

protected function _toHtml()
{
    if (!$this->getCount()) {
        return '';
    }
    $this->setRecentlyViewedProducts($this->getItemsCollection());
    return parent::_toHtml();
}

If you venture into the function Mage_Reports_Block_Product_Abstract::getItemsCollection what you will see is that it builds the product collection. There are a few things to take note here.

Limit by customer

If there is a customer id then it adds the filter to the collection.

if ($this->getCustomerId()) {
    $this->_collection->setCustomerId($this->getCustomerId());
}

Excludes some products

There is an exclusion of some products.

$this->_collection->excludeProductIds($this->_getModel()->getExcludeProductIds())

But for products viewed it simply excludes the current product being viewed if there is one.

Using this information I think you will be able to look into the functions and debug what is actually going wrong with your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.