1

I've got this issue.
I'm building a multiwebsite shop with magento 1.9.2. I've modified the index php to auto detect language and insert language code in url following this:
https://gist.github.com/arosenhagen/5256617

here my index.php version:

<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magento.com for more information. * * @category Mage * @package Mage * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ if (version_compare(phpversion(), '5.3.0', '<')===true) { echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;"> <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"> <h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;"> Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.3.0 or newer. <a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>'; exit; } /** * Compilation includes configuration file */ define('MAGENTO_ROOT', getcwd()); $compilerConfig = MAGENTO_ROOT . '/includes/config.php'; if (file_exists($compilerConfig)) { include $compilerConfig; } $mageFilename = MAGENTO_ROOT . '/app/Mage.php'; $maintenanceFile = 'maintenance.flag'; if (!file_exists($mageFilename)) { if (is_dir('downloader')) { header("Location: downloader"); } else { echo $mageFilename." was not found"; } exit; } if (file_exists($maintenanceFile)) { include_once dirname(__FILE__) . '/errors/503.php'; exit; } require MAGENTO_ROOT . '/app/bootstrap.php'; require_once $mageFilename; #Varien_Profiler::enable(); if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) { Mage::setIsDeveloperMode(true); } #ini_set('display_errors', 1); umask(0); /* Language detection */ function getLanguageCode() { $default_language_code = ''; if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { foreach (explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $accept) { if (preg_match("!([a-z-]+)(;q=([0-9.]+))?!", trim($accept), $found)) { $langs[] = $found[1]; $quality[] = (isset($found[3]) ? (float) $found[3] : 1.0); } } // Order the codes by quality array_multisort($quality, SORT_NUMERIC, SORT_DESC, $langs); // get list of stores and use the store code for the key $host = $_SERVER['HTTP_HOST']; if (strpos($host,'baseDomain') > -1){ $stores = Mage::app()->getWebsite(1)->getStores(false, true); $langPrefix ='r_'; } elseif (strpos($host,'aliasDomain') > -1) { $stores = Mage::app()->getWebsite(2)->getStores(false, true); $langPrefix ='a_'; } foreach ($stores as $store) { $stores[$store->getCode()] = $store; } // iterate through languages found in the accept-language header foreach ($langs as $lang) { $lang = $langPrefix . substr($lang,0,2); if (isset($stores[$lang]) && $stores[$lang]->getIsActive()) return $lang; } } return $default_language_code; } if ( strpos($_SERVER['REQUEST_URI'], "/it/") !== false ) { $url_lang = 'it'; } else if ( strpos($_SERVER['REQUEST_URI'], "/fr/") !== false ) { $url_lang = 'fr'; } else if ( strpos($_SERVER['REQUEST_URI'], "/de/") !== false ) { $url_lang = 'de'; } else if ( strpos($_SERVER['REQUEST_URI'], "/es/") !== false ) { $url_lang = 'es'; } else { $url_lang = 'en'; # which is the default language of the default store of your installation (/) } $store_code = getLanguageCode(); $_SERVER['REQUEST_URI'] = preg_replace("#^/$url_lang(/.*)#i",'$1',$_SERVER['REQUEST_URI']); if ( ! preg_match('#^/index.php/admin/#i',$_SERVER['REQUEST_URI']) ) { $_GET['___store'] = $store_code; } /* Store or website code */ $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : $store_code; /* Run store or run website */ $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; Mage::run($mageRunCode, $mageRunType); 

Now when I add a product to compare list I come redirected to the home page.
After check for this bug I found out this issue come from this function :

protected function _getRefererUrl() { $refererUrl = $this->getRequest()->getServer('HTTP_REFERER'); if ($url = $this->getRequest()->getParam(self::PARAM_NAME_REFERER_URL)) { $refererUrl = $url; } if ($url = $this->getRequest()->getParam(self::PARAM_NAME_BASE64_URL)) { $refererUrl = Mage::helper('core')->urlDecodeAndEscape($url); } if ($url = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) { $refererUrl = Mage::helper('core')->urlDecodeAndEscape($url); } if (!$this->_isUrlInternal($refererUrl)) { $refererUrl = Mage::app()->getStore()->getBaseUrl(); } return $refererUrl; } 

on app\code\core\Mage\Core\Controller\Varien\Action.php
This function doesn't reconize the refererURL generate by

$refererUrl = Mage::helper('core')->urlDecodeAndEscape($url); 

as an internal url because the language code disappear:

  • expected url : baseDomain/it/productsCategory.html
  • given url : baseDomain/productsCategory.html

If i comment out this

if ($url = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) { $refererUrl = Mage::helper('core')->urlDecodeAndEscape($url); } 

everything works fine but guess could be a big mistake to do so.

So my question is: How can i get the full path with language code in the encoded url generated by compare link?

1 Answer 1

1

I solved the issue modifing getCurrentUrl Function in
app/code/core/Mage/Core/Helper/Url.php on line 53

$url = $request->getScheme() . '://' . $request->getHttpHost() . $port . $request->getServer('REQUEST_URI'); 

with

$url = $request->getScheme() . '://' . $request->getHttpHost() . $port . '/' . preg_replace('/.*_(.*)/','$1',Mage::app()->getStore()->getCode()) . $request->getServer('REQUEST_URI'); 

with override the file in app/code/local/Mage/Core/Url.php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.