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 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了