doudanma9706 2013-06-21 14:32 采纳率: 100%
浏览 9
已采纳

在Magento 1.7中直接从其他商店语言链接时,产品URL会返回404错误

My magento store has 3 languages. If someone links me a product from the "English" store view for example, and I'm on the "Spanish" store view, that product returns a 404 error.

So far in my investigation I've found this blog, but I'm currently trying to understand where that code goes. I understand it's in the file /app/code/core/Mage/Core/Model/Url/Rewrite.php but I can't figure out where exactly in that file I should add that code snippet.

And I ain't even certain that will solve my problem.

Edit:

Ok, I've found this link: http://freegento.com/doc/db/d5d/_url_2_rewrite_8php-source.html

According to this, my file should have something similar to what I saw in the blog above, unfortunately, the function loadByRequestPath on my file is different and it goes like this:

/**
 * Load rewrite information for request
 * If $path is array - we must load possible records and choose one matching earlier record in array
 *
 * @param   mixed $path
 * @return  Mage_Core_Model_Url_Rewrite
 */
public function loadByRequestPath($path)
{

    $this->setId(null);
    $this->_getResource()->loadByRequestPath($this, $path);
    $this->_afterLoad();
    $this->setOrigData();
    $this->_hasDataChanges = false;
    return $this;
}
  • 写回答

1条回答 默认 最新

  • dqy0707 2013-06-21 14:48
    关注

    Ok, that was quick! I solved my problem by replacing the loadByRequestPath located in the file /app/code/core/Mage/Core/Model/Url/Rewrite.php to this:

    public function loadByRequestPath($path)
         {
             $this->setId(null);
    
             if (is_array($path)) {
                 foreach ($path as $pathInfo) {
                     $this->load($pathInfo, 'request_path');
                        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();
                            }
                        }
                    }
                 }
             }
             else {
                 $this->load($path, 'request_path');
             }
             return $this;
         }
    

    Don't forget to make a local copy if you don't want any problems when upgrading Magento.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥20 win11无法启动 持续蓝屏且系统还原失败,无法开启系统保护
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码