The problem is a bug in the model Mage_Core_Model_Url_Rewrite_Request
(Magento 1.8) and Mage_Core_Model_Url_Rewrite
(earlier versions).
The section of core code in 1.8 looks like this:
// Section from Mage_Core_Model_Url_Rewrite_Request::_rewriteDb()
$fromStore = $this->_request->getQuery('___from_store');
if (!$this->_rewrite->getId() && $fromStore) {
$stores = $this->_app->getStores();
if (!empty($stores[$fromStore])) {
$store = $stores[$fromStore];
$fromStoreId = $store->getId();
} else {
return false;
}
The Bug: the value of the query parameter is the store code, (in my case de
, en
or fr
).
The keys of the array returned by app->getStores()
are the numeric store IDs.
Thats why if (!empty($stores[$fromStore])) {
always fails.
Once that bug is fixed, another bug becomes apparent later in the same method (I think only in 1.8):
$targetUrl = $this->_request->getBaseUrl() . '/' . $this->_rewrite->getRequestPath();
The request objects base url always is the Magento base_url, without the store code.
Using $currentStore->getBaseUrl()
instead there fixes that bug, too.
Once those two issues are fixed the language switcher works fine. Here is an extension which does exactly that for Magento 1.8 (CE): https://github.com/Vinai/VinaiKopp_StoreUrlRewrites
In Magento 1.7 the issue might be something different. I still thought I'd add this answer, just in case google brings somebody else here who is running 1.8 or newer.
I think the simplest solution here will be to create 301 redirects for your pages in different languages in the url rewrites management admin section.
Something like this:
For DE store view redirect from bags.html
to taschen.html
.
For EN store view redirect from taschen.html
to bags.html
.
Do the same for all the other combinations.
this way, when you switch from domain.com/en/bags.html
to DE you it will points to a page that does not exist domain.com/de/bags.html
but that will do a 301 redirect to domain.com/de/taschen.html
.
I know that there are a lot of redirects to create, but I can recommend you this extension. All you need to do is to provide the url keys for each store view and it will create automatically the redirects.
But if you don't like this approach, you may need to rewrite the Mage_Core_Model_Store::getCurrentUrl
method to look in the url_rewrites
table and get the url for each language. But this may cause performance issues and it is not a bullet proof solution, because it will not work for cms pages or other custom page.
I don't have a full working solution for this, but I can give you some pointers.
Look in the core_url_rewrites
table for a target path matching the $requestString
var in the method mentioned above for the store that should generate the url and append to the target path value the query string.
Best Answer
You missing one underscore in the parameter name. It should be
___store={storeview_code}
Also, all state modifications should happen using POST request. Otherwise, the page might be cached by varnish or built-in cache.