Magento, Shopper theme and VTO
Last week I have updated bennewitz.com and I was able to fix a long time bug of Magento. The problem appears when I change the language from German to English. The names of the catergories are different – that’s why I receive an 404 error. There was no translation of the category name, based by the category ID.
This is a very nasty error.
Looking into the code I found that I had removed the “?___from_store=xx”output in past for better SEO: Inside of /app/design/frontend/base/default/template/page/switch/languages.phtml “getCurrentUrl()” was set to “getCurrentUrl(false)”.
This was a bad idea because this avoids the translation of the category name. However setting this back to default the language switcher doesn’t work as expected. Even the category name is translated the store code is still missed.
In result I had to look some deeper inside the php… for Magento 1.7.0.2 I have found this fix:
/app/code/core/Mage/Core/Model/Url/Rewrite.php
Starting from line 251 I have replaced the default assignment to $targetUrl
Mage::app()->getCookie()->set(Mage_Core_Model_Store::COOKIE_NAME, $currentStore->getCode(), true);
// endur 02-03-2013 fix for missed store code
// $targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();
if (Mage::getStoreConfig('web/url/use_store') && $storeCode
= Mage::app()->getStore()>getCode()) {
$targetUrl = $request->getBaseUrl(). '/'
. $storeCode . '/' .$this->getRequestPath();
} else {
$targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath();
}
// endur 02-03-2013 end
to get the store code added. It seem’s a bug of Magento 1.7.0.2.
Of course I havn’t change the core file itself, I have changed a copy instead:
/app/code/local/Mage/Core/Model/Url/Rewrite.php
…and the language switcher is working well from now