Magento语言切换器:未在url中翻译类别名称

Magento语言切换器:未在url中翻译类别名称,magento,categories,language-switching,Magento,Categories,Language Switching,我有一个商店,有两种语言的商店视图,意大利语和英语 对于某些类别,我有不同的意大利语和英语名称,比如EN的Apparel和Abbigliamento 问题是,当我在mystore.com/it/abbigliamento时,如果我将语言切换为英语,语言切换程序会将我带到mystore.com/en/abbigliamento而不是mystore.com/en/apparel,并给我一个404错误 语言切换器更改商店id,但不翻译类别名称 谢谢你,皮埃特罗。在magento管理中 Catalog-

我有一个商店,有两种语言的商店视图,意大利语和英语

对于某些类别,我有不同的意大利语和英语名称,比如EN的Apparel和Abbigliamento

问题是,当我在mystore.com/it/abbigliamento时,如果我将语言切换为英语,语言切换程序会将我带到mystore.com/en/abbigliamento而不是mystore.com/en/apparel,并给我一个404错误

语言切换器更改商店id,但不翻译类别名称

谢谢你,皮埃特罗。

在magento管理中

Catalog->Manage categories
选择类别,然后选择首选门店视图。您应该在那里编辑并保存“URL键”参数


如果它仍然显示旧的url-清除缓存并使url重写重新索引。

您可以对
Mage\u Core\u Model\u存储使用重写,如下所示

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, '', '&') : '');
}

}

已经完成,url工作正常。问题是语言切换器在切换url中输入了错误的“category url key”。提供工作url的函数是$\u lang->getCurrentUrl(false)在add/design/frontend/base/default/template/page/switch/languages.phtml中,谢谢:)刚刚找到了这个问题的magento问题这里有一个关于这个问题的论坛线程链接现在已经死了:-(但我发布了一个答案\o/