I experienced 404 pages for products after user session expiration. You can read the steps to reproduce the bug here:
http://www.magentocommerce.com/bug-tracking/issue/index/id/541
What is the fix for that?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI experienced 404 pages for products after user session expiration. You can read the steps to reproduce the bug here:
http://www.magentocommerce.com/bug-tracking/issue/index/id/541
What is the fix for that?
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"?>
<config>
<modules>
<George_Solution>
<active>true</active>
<codePool>local</codePool>
</George_Solution>
</modules>
</config>
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:
<config>
<global>
<models>
<reports_resource>
<rewrite>
<helper_mysql4>George_Solution_Reports_Model_Resource_Helper_Mysql4</helper_mysql4>
</rewrite>
</reports_resource>
</models>
</global>
</config>
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:
<?php
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:
app---etc---modules---George_Solution.xml
|
--code---local---George---Solution---etc---config.xml
|
--Reports-
|-Model-
|-Resource-
|-Helper---Mysql4.php
You can verify that this function is working by:
mergeVisitorProductIndex
, add a Mage::log() statement. I added one in the example above. Just uncomment the line.In file
app/code/core/Mage/Reports/Model/Resource/Helper/Mysql4.php
Change line 48 from:
$result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, array_keys($data));
to:
$result = $this->_getWriteAdapter()->insertOnDuplicate($mainTable, $data, $matchFields);