I am trying to display a message in template when there are no viewed_products. So I have tried to overwrite class Mage_Reports_Block_Product_Viewed and its method like this.
Module etc/config.xml file
<config>
<global>
<blocks>
<reports>
<rewrite>
<product_viewed>Myclass_Overwrites_Block_Reports_Product_Viewed</product_viewed>
</rewrite>
</reports>
</blocks>
</global>
</config>
Block in app/code/local/Myclass/Overwrites/Block/Product/Viewed.php
class Myclass_Overwrites_Block_Reports_Product_Viewed extends Mage_Reports_Block_Product_Viewed
{
...
protected function _toHtml(){
if ($this->getCount()) {
$this->setRecentlyViewedProducts($this->getItemsCollection());
}
return parent::_toHtml();
}
...
}
Now it overwrites it, if i click on a product and refresh the page i can clearly see with debuging ON that its getting overwritten and that product is shown. But if i don't click on a product (if visited product/s arent stored) it doesnt show anything (i guess it runs the class from Core, i also tried to change it just to see if it would work in core files and it does). I am doing this because i want to show else statement from template
Template design/frontend/Project/default/template/reports/product_viewed.phtml
<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
//Code if there are Viewed Products
<?php else: ?> // This doesn't show
<div class="block block-list block-viewed row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="block-title panel-heading">
<h3 class ="panel-title"><span><?php echo $this->__('Recently Viewed Products') ?></span></h3>
</div>
<div class="block-content panel-body">
<p>You haven't viewed any Products</p>
</div>
</div>
</div>
Am i doing something wrong or could i do this some other way?