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.

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化