2012-02-20 6 views
0

イタリア語と英語の2つの言語で2つの店舗ビューがあるストアがあります。Magento言語スイッチャー:カテゴリ名がURLに翻訳されていない

一部のカテゴリでは、イタリアのアパレルやENのAbbigliamento ITのように、イタリア語と英語の名前が異なります。

問題は、私がmystore.com/it/abbigliamentoに英語を切り替えると言語切り替えがmystore.com/en/abbigliamentoにmystore.com/en/apparelの代わりに来てくれて私は404エラー。

言語スイッチャーは、ストアIDを変更しますが、カテゴリ名に

おかげで、ピエトロは翻訳されません。

+0

http://www.magentocommerce.com/bug-tracking/issue/?issue=12829ここ – pietrosld

+0

問題についてのフォーラムスレッドhttp://www.magentocommerce.com/boards/viewthread/9771/P75/ – pietrosld

+0

リンクは今死んでいます:-(しかし、私は答えを投稿しました\/ – Alex

答えて

-1

Catalog->Manage categories 

選択したカテゴリでMagentoの管理者で

と兼ね備え店舗ビューを選択します。ここで、「URLキー」パラメータを編集して保存する必要があります。

まだ古いURLが表示される場合は、キャッシュをクリアしてURLを書き換えます。

+1

は既に、URLは正常に動作している問題は、言語スイッチャがスイッチURLに間違った "カテゴリURLキー"を入れたことです。 URLを与える機能は、add/desの** $ _ lang-> getCurrentUrl(false)**です。 ign/frontend/base/default/template/page/switch/languages.phtml とにかく:) – pietrosld

2

次のようにあなたがMage_Core_Model_Storeためのリライトを使用することができ、この問題のためにちょうど今Magentoの問題を発見した

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

ありがとうございました! –