HummingbirdUK main logo

Coding solutions to business problems

About us

We use code to create solutions to business challenges, bottle-necks and headaches.

If you think your business has a problem that can be solved through code, we are happy to chat things through without any obligation.

Get in touch

Clear most viewed products list in Magento

Home / Blog / Clear most viewed products list in Magento

Written by Giles Bennett

In an earlier post I wrote about how to clear test data out from a store - it would appear that a lot of people are looking specifically for a way to clear the 'most viewed' products list or 'recently viewed' products list from Magento.

Below is a simple script to do just that, even if you don't have direct access to the database (through phpMyAdmin, or similar).

Start off in the usual way :

<?php 
require_once('app/Mage.php');
Mage::app('default');

Then connect to the database :

$resource = Mage::getSingleton('core/resource')->getConnection('core_read'); 

And then get the relevant table name (this method of doing so takes into account any prefix that you may have set for your database tables) :

$tableName = $resource->getTableName('report_event');

Finally, truncate the table and report back that that's been done :

$resource->query("truncate table " . $tableName); 
echo $tableName . " has been truncated";
?>

And that's it. Of course, if you do have direct database access then just use the mySQL command 'truncate table report_event;'' to get the same effect. Entirely up to you!

Author : Giles Bennett

About the author

Giles Bennett built his first website in 1996, and is old enough to miss Netscape Navigator. Initially a lawyer, he jumped ship to IT in 2008, and after 5 years as a freelancer, he founded HummingbirdUK in 2013. He can be reached by email at giles@hummingbirduk.com.