Magento多语言-404中语言结果的双重更改(或如何在商店而不是视图中更改语言) [英] Magento multilanguage - double change in language resuts in 404 (or how to change language within stores not views)

查看:89
本文介绍了Magento多语言-404中语言结果的双重更改(或如何在商店而不是视图中更改语言)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装magento时遇到问题.我使用了Magento ver. 1.5.0.1,用于开发此网站的社区版本 http://cissmarket.com/.

I have a problem with a magento installation. I used Magento ver. 1.5.0.1, community edition to develop this website http://cissmarket.com/.

当我将语言从欧盟版本更改为法语,然后将其更改为德语时,就会出现问题.更改为法语是可以的,但是当我在同一页面中更改为德语时,会收到404错误.另外,这是Google网站管理员工具中的404错误,当我尝试例如获取此链接并将其粘贴到浏览器中时,它也给我404错误.我在Google网站管理员工具中有大约50种产品和大约550404错误.我了解问题出在我的描述中.

The problem appears when I change the language from the EU version to French and after that to German. The change to french is ok, but when in the same page i change to German i receive a 404 error. Also this is generation 404 errors in the Google webmaster tools and when i try for example to take this link and paste it in the browser it gives me also a 404 error. I have there some 50 products and ~550 404 errors in Google Webmaster tools. I understand that the problem is from what I described.

此外,由于我有此法语页面,因此我遇到了SEO问题:

Moreover I have a SEO problem since 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 takes me to this link

> http://cissmarket.com/de/cartouches-refilables.html ?___ from_store = fr (如果我现在尝试切换到英国,我会得到上面提到的404)

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

而不是去这个:

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

已经检查了此 404错误当在magento上的类别中在商店之间切换时,但这与我的问题无关.

Already checked this 404 error when switching between stores when in a category on magento but it does not relate to my problem.

关于设置:

  • 我使用了缓存服务,并且也为所有内容建立了索引.
  • 我尝试访问的产品或类别可用,并且已针对所有语言设置为有效.
  • 系统>常规> Web> URL选项>已将商店代码添加到Urls中 对.
  • 系统>常规> Web>搜索引擎优化>使用Web服务器 重写设置为是.
  • 除了.htaccess文件外,没有对.htaccess文件进行任何其他更改. 系统本身制作的.
  • I use the caching service and also I did index all the content.
  • The product or category I am trying to access is available and set active for all the languages.
  • System > General > Web > URL options > Add Store Code to Urls is set to yes.
  • System > General > Web > Search Engines Optimization > Use Web Server Rewrites is set to yes.
  • No other changes has been made to the .htaccess file except for the ones that the system itself made.

因此可以得出结论:问题是当我从一页切换到另一页时,两次语言的连续更改和错误的url地址给出的404.

So to conclude: the problem is the 404 given by 2 succesive changes of the language and the bad url address when I switch from one page to another.

任何建议将不胜感激.

更新:尝试了 http://www.activo.com/how-to-a-void-the-___from_store-query-parameter-when-switching-store-views-in-magento ,但结果为404第一次更改语言

UPDATE: tried this http://www.activo.com/how-to-avoid-the-___from_store-query-parameter-when-switching-store-views-in-magento but it results in a 404 at the first language change

编辑#1:

发现了问题:文件language.phtml包含此代码<?php echo str_replace ("/fr/","/de/",$_lang->getCurrentUrl()); ?>,实际上根据相应的翻译,它仅替换了语言代码,而不替换了整个url.

Found the problem: file languages.phtml contained this code <?php echo str_replace ("/fr/","/de/",$_lang->getCurrentUrl()); ?> and actually did replace only the language code and not the whole url according to the corresponding translation.

因此适用于此

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

它将返回

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

那么有谁知道如何获取商店中可用的其他语言的当前页面的对应URL?

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

编辑#2(使用@Vinai解决方案):

Edit #2 (using @Vinai solution):

它适用于产品页面,但不适用于类别.

It works on the product pages but not on the category yet.

推荐答案

据我所知,原生Magento中没有这样的东西.
也就是说,您可以使用以下代码来获取每个商店的当前页面URL.

There is no such thing in the native Magento as far as I know.
That said, 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);

这将为您提供一个数组,其中数组键是商店ID,数组值是在Magento基本URL后的请求路径,例如假设您的法国商店的ID为1,德国商店的ID为2,您将获得:

This will give you an array with the array key being the store IDs and the array values being the request path after the Magento base URL, e.g. assuming your French store has the ID 1 and the German one has the ID 2, you would get:

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

然后,在输出每个商店的URL的foreach循环中,使用

Then, in the foreach loop where the URL for each store is output, use

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

$_lang->getUrl()的调用将添加基本URL,因此您将获得每个商店的完整URL(例如,

The 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 store view value is found in the core_url_rewrite table it will revert to the default behaviour.

您仍然需要___store=fr查询参数,因为否则Magento会认为您正在尝试在旧商店的上下文中访问新路径.幸运的是,getUrl()商店模型调用会自动为您添加该模型.

You still need the ___store=fr query parameter because otherwise Magento will think you are trying to access the new path in the context of the old store. Luckily, the getUrl() call an the store model adds that for you automatically.

查询数据库的代码当然可以在任何地方(因为它是PHP),即使在模板中也可以,但是请不要放在那里. 拥有访问数据库代码的正确位置是资源模型.我建议您创建一个资源模型并将其放在其中的方法中.

The code querying the database can be anywhere of course (since its PHP), even in the template, but please don't put it there. The correct place to have code that access the database is a resource model. I suggest you create a resource model and put it in a method there.

这篇关于Magento多语言-404中语言结果的双重更改(或如何在商店而不是视图中更改语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆