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!