Magento multilanguage - a double change of language solves in 404 (or how to change the language in stores, not in views)

I have a problem installing magento. I used Magento ver. 1.5.0.1, a community publication for the development of this website http://cissmarket.com/ .

The problem arises when I change the language from the EU version to French, and then to German. The change to French is normal, but when I switch to German on the same page, I get a 404 error. In addition, these are 404 generation errors in Google’s webmaster tools, and when I try, for example, to take this link and paste it into browser, it also gives me 404 error. I have about 50 products and ~ 550 404 errors in Google webmaster tools. I understand that the problem is what I described.

In addition, I have a problem with SEO, as I have this page in French:

http://cissmarket.com/de/cartouches-refilables.html

And when I switch to the German version of the website, it will lead me to this link

http://cissmarket.com/de/cartouches-refilables.html?___from_store=fr (if I try to switch to uk now, I will get the 404 mentioned above)

instead of this:

http://cissmarket.com/de/nachfullpatronen.html

Error 404 has already been checked when switching between stores when in a category on magento , but this does not apply to my problem.

About settings:

  • I use the caching service and also indexed all the content.
  • The product or category I'm trying to access is available and installed for all languages.
  • System> General> Web Settings> URL Settings> Add Store Code for URLs yes.
  • System> General> Web> Search Engine Optimization> Using Web Server Rewrites is set to yes.
  • No other changes were made to the .htaccess file, except for which the system itself made.

So the problem is that the problem is the 404 given by two consecutive language changes and the wrong URL when switching from one page to another.

Any suggestions would be appreciated.

UPDATE: tried this http://www.activo.com/how-to-avoid-the-___from_store-query-parameter-when-switching-store-views-in-magento , but this leads to 404 on the first change of language

Edit # 1:

Found a problem: languages.phtml file contained this code <?php echo str_replace ("/fr/","/de/",$_lang->getCurrentUrl()); ?> <?php echo str_replace ("/fr/","/de/",$_lang->getCurrentUrl()); ?> and actually replaced only the language code, and not the entire url in accordance with the corresponding translation.

Therefore applied to this

http://cissmarket.com/fr/cartouches-refilables.html

he will return

http://cissmarket.com/de/cartouches-refilables.html

Does anyone know how to get the corresponding URL of the current page for other languages ​​available in the store?

Edit # 2 (using @Vinai's solution):

It works on the product pages, but does not belong to the category.

+4
source share
6 answers
As far as I know, this is not in the native Magento. However, you can use the following code to get the current page URL for each store.
 $resource = Mage::getSingleton('core/resource'); $requestPath = Mage::getSingleton('core/url')->escape( trim(Mage::app()->getRequest()->getRequestString(), '/') ); $select = $resource->getConnection('default_read')->select() ->from(array('c' => $resource->getTableName('core/url_rewrite')), '') ->where('c.request_path=?', $requestPath) ->where('c.store_id=?', Mage::app()->getStore()->getId()) ->joinInner( array('t' => $resource->getTableName('core/url_rewrite')), "t.category_id=c.category_id AND t.product_id=c.product_id AND t.id_path=c.id_path", array('t.store_id', 't.request_path') ); $storeUrls = (array) $resource->getConnection('default_read') ->fetchPairs($select); 

This will give you an array with the array key being the store identifiers, and the array values ​​are the request path after the Magento base URL, for example. if your French store has identifier 1, and the German has ID 2, you will receive:

 Array ( [1] => cartouches-refilables.html [2] => nachfullpatronen.html ) 

Then in the foreach , where the URL for each repository is displayed, use

 <?php $url = isset($storeUrls[$_lang->getId()]) ? $_lang->getUrl($storeUrls[$_lang->getId()]) : $_lang->getCurrentUrl() ?> 

A call to $_lang->getUrl() will add the base URL, so you will get the full URL for each store (e.g. http://cissmarket.com/de/nachfullpatronen.html ) If no value is found in the core_url_rewrite table view of the repository, it will revert to the default behavior.

You still need the request parameter ___store=fr , because otherwise Magento will think that you are trying to access the new path in the context of the old repository. Fortunately, a call to getUrl() creates a store model that is automatically added to it.

The code requesting the database can be anywhere (starting with its PHP), even in the template, but please do not put it there. The right place to access the database is the resource model . I suggest you create a resource model and put it in a method.

+7
source

I found an ugly patch until a better approach comes up.

In the admin section, I added the following javascript inside wysiwyg in CMS> PAGES> (My 404 pages) (at the beginning of wysiwyg):

 <script type="text/javascript" language="javascript">// <![CDATA[ var lang = "en"; var rooturl = "{{config path="web/unsecure/base_url"}}" var url = document.location.href; if(!(url.match("/"+lang+"/"))) { var newUrl = url.replace(rooturl , rooturl+lang+"/" ); window.location.href = newUrl; } // ]]></script> 

<i> (Note: you need to do this for all 404 pages translated. On each 404 page, you need to change lang = "en" for your storeview url value)

Since wysiwyg (tiny_mce) does not allow javascript to be processed, you will have to change js / mage / adminhtml / wysiwyg / tinymce / setup.js . Add the following code to line 97 (under "var settings ="):

 extended_valid_elements : 'script[language|type|src]', 
+3
source

For Magento 1.7.0.2 and 1.8.0.0 this fix is:

Starting at line 251 / app / code / core / Mage / Core / Model / Url / Rewrite.php

:

 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 

Be sure to create a custom copy of the file in: /app/code/local/Mage/Core/Model/Url/Rewrite.php or: /app/code/local/YourTheme/Mage/Core/Model/Url/Rewrite.php

source:

+1
source

Here is another solution to this problem. Just add this code after "$ this-> load ($ pathInfo, 'request_path'); in the application /code/core/Mage/Core/Model/Url/Rewrite.php:

  if (!$this->getId() && !isset($_GET['___from_store'])) { $db = Mage::getSingleton('core/resource')->getConnection('default_read'); $result = $db->query('select store_id from core_url_rewrite WHERE request_path = "' . $pathInfo . '"'); if ($result) { $storeIds = array(); if($row = $result->fetch(PDO::FETCH_ASSOC)) { $storeId = $row['store_id']; $storeCode = Mage::app()->getStore($storeId)->getCode(); header("HTTP/1.1 301 Moved Permanently"); header("Location: http://" . $_SERVER['HTTP_HOST'] . "/" . $pathInfo . "?___store=" . $storeCode); exit(); } } } 
0
source

Sounds like a bug in Magento 1.7. Here is the hack that worked for me. It should work in two language repositories with the store code in the URL

in var / www / html / shop1 / app / code / core / Mage / Core / Model / Url / Rewrite.php

delete this line

  // $targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath(); 

and add them:

  $storecode = Mage::app()->getStore()->getCode(); if ($storecode='en') { $targetUrl = $request->getBaseUrl(). '/'.$storecode.'/' . $this->getRequestPath(); } else { $targetUrl = $request->getBaseUrl(). '/' . $this->getRequestPath(); } 
0
source

guys. There is a magenta module for this error. He rewrote 2 models http://www.magentocommerce.com/magento-connect/fix-404-error-in-language-switching.html

0
source

Source: https://habr.com/ru/post/1394181/


All Articles