I experienced 404 pages for products after user session expiration. You can read the steps to reproduce the bug here:


What is the fix for that?

2 Answers 2


In the file app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php there is a function called mergeVisitorProductIndex(). Instead of editing the core to change this function, you should override the resource Helper. This is a little different than overriding a standard helper but really only in the syntax of the config.xml.

First, create a small extension.

In app/etc/modules add a file called George_Solution.xml.

George_Solution.xml contents:

<?xml version="1.0"?>

The codePool is "local" which means your module will be in "app/code/local" and George_Solution means that it will be in "George/Solution". Placing this file in "app/etc/modules" tell Magento where to look for your extension.

Next, create the file structure for your extension. Go to "app/code/local" and create a folder called "George". Inside of George, create another folder called "Solution". The full path will be "app/code/local/George/Solution/".

Now create your config.xml file inside of "etc". The full path will be "app/code/local/George/Solution/etc/config.xml".

config.xml contents:


Now that you have the Resource Helper extended, you can add your changed function. You only need to add the function that you have changed something in.

Create the file structure: George/Solution/Reports/Model/Resource/Helper

In the Helper folder, create Mysql4.php

Mysql4.php contents:


class George_Solution_Reports_Model_Resource_Helper_Mysql4 extends Mage_Reports_Model_Resource_Helper_Mysql4 {

    public function mergeVisitorProductIndex($mainTable, $data, $matchFields) {

        // Mage::log("My mergeVisitorProductIndex works!");

        // Old line: $result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, array_keys($data));

        // Your new line:
        $result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, $matchFields);

        return $result;


The entire extension structure is:


You can verify that this function is working by:

  1. Turn on System logging
  2. In the function mergeVisitorProductIndex, add a Mage::log() statement. I added one in the example above. Just uncomment the line.
  3. Go to a product page and add a product to Compare. Then navigate to another product and add it to Compare.
  4. Go to var/log/system.log to see the message from the Mage::log().
  • Awesome! Thank you so much Sean! I will send you an email.
    – george
    Jan 27, 2015 at 15:11

In file


Change line 48 from:

$result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, array_keys($data));


$result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, $matchFields);
  • You should never edit the core. It is very easy to override a Helper. There's many resources out there explaining how to do this. Jan 25, 2015 at 0:44
  • I am not a Magento developer per se. I know only how to make my own templates for frontend. I found a serious bug, spent a lot of time on it and published the solution. If you know how to fix that in a better way, could you please share?
    – george
    Jan 26, 2015 at 8:01

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.