2012-02-20 88 views
0

我有一家商店,有两种语言的意大利语和英语两种商店的意见。Magento语言切换器:类别名称未在url中翻译

对于某些类别,我对意大利语和英语有不同的名称,例如针对EN的服装和针对IT的Abbigliamento。

问题是,当我在mystore.com/it/abbigliamento如果我将语言切换到英语语言切换器将我带到mystore.com/en/abbigliamento而不是mystore.com/en/apparel,并给出我404错误。

语言切换改变店铺ID,但不翻译的类别名称

感谢,彼得。

+0

发现刚才Magento的问题,对于这个问题http://www.magentocommerce.com/bug-tracking/issue/?issue=12829 – pietrosld 2012-02-21 21:14:51

+0

这里关于这个问题的论坛主题http://www.magentocommerce.com/boards/viewthread/9771/P75/ – pietrosld 2012-02-21 21:21:02

+0

链接现在已经死了:-(但是我发布了一个答案\ o/ – Alex 2016-03-24 12:25:49

回答

-1

在Magento管理中

Catalog->Manage categories 

选择类别,然后选择较受欢迎的商店视图。在那里你应该编辑并保存“URL key”参数。

万一它仍然显示旧的URL - 清理缓存并使URL重写reindex。

+1

已经完成了,网址工作正常。问题在于,语言切换器在切换URL中输入错误的“类别URL密钥” 给我工作的函数是** $ _lang-> getCurrentUrl(false)** in add/des ign/frontend/base/default/template/page/switch/languages.phtml thankyou无论如何:) – pietrosld 2012-02-21 08:32:43

2

你可以使用一个重写的Mage_Core_Model_Store如下

class Example_StoreUrls_Model_Core_Store extends Mage_Core_Model_Store { 


/** 
* Looks up a given request path in the current store (app) and translates it to the 
* value in $this store using the rewrite index 
* 
* You might want to throw exceptions in case of just returning the input URLs during errors. 
* 
* @param $requestPath 
*/ 
public function lookupLocalizedPath($requestPath) { 
    $urlRewriteCollectionSource = Mage::getModel('core/url_rewrite')->getCollection(); 
    $urlRewriteCollectionSource 
     ->addFieldToFilter('request_path', $requestPath) 
     ->addStoreFilter(Mage::app()->getStore()); 
    if(count($urlRewriteCollectionSource) == 0) { 
     return $requestPath; 
    } 

    $idPath = $urlRewriteCollectionSource->getFirstItem()->getIdPath(); 

    $urlRewriteCollectionTarget = Mage::getModel('core/url_rewrite')->getCollection(); 
    $urlRewriteCollectionTarget 
     ->addFieldToFilter('id_path', $idPath) 
     ->addStoreFilter($this); 

    if(count($urlRewriteCollectionTarget) == 0) { 
     return $requestPath; 
    } 

    return $urlRewriteCollectionTarget->getFirstItem()->getRequestPath(); 
} 

/** 
* Copied from parent + change: 
* Watch out for the inserted line 

* @param bool $fromStore 
* @return string 
*/ 
public function getCurrentUrl($fromStore = true) 
{ 
    $sidQueryParam = $this->_getSession()->getSessionIdQueryParam(); 
    $requestString = Mage::getSingleton('core/url')->escape(
     ltrim(Mage::app()->getRequest()->getRequestString(), '/')); 

    $storeUrl = Mage::app()->getStore()->isCurrentlySecure() 
     ? $this->getUrl('', array('_secure' => true)) 
     : $this->getUrl(''); 
    $storeParsedUrl = parse_url($storeUrl); 

    $storeParsedQuery = array(); 
    if (isset($storeParsedUrl['query'])) { 
     parse_str($storeParsedUrl['query'], $storeParsedQuery); 
    } 

    $currQuery = Mage::app()->getRequest()->getQuery(); 
    if (isset($currQuery[$sidQueryParam]) && !empty($currQuery[$sidQueryParam]) 
     && $this->_getSession()->getSessionIdForHost($storeUrl) != $currQuery[$sidQueryParam] 
    ) { 
     unset($currQuery[$sidQueryParam]); 
    } 

    foreach ($currQuery as $k => $v) { 
     $storeParsedQuery[$k] = $v; 
    } 

    // inserted the following line - rest is from core 
    $requestString = $this->lookupLocalizedPath($requestString); 

    if (!Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getCode())) { 
     $storeParsedQuery['___store'] = $this->getCode(); 
    } 
    if ($fromStore !== false) { 
     $storeParsedQuery['___from_store'] = $fromStore === true ? Mage::app()->getStore()->getCode() : $fromStore; 
    } 

    return $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] 
    . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') 
    . $storeParsedUrl['path'] . $requestString 
    . ($storeParsedQuery ? '?'.http_build_query($storeParsedQuery, '', '&') : ''); 
} 

} 
+0

谢谢,工作正常! – 2016-05-19 06:43:48