0

イタリア語と英語の 2 つの言語の 2 つのストア ビューを持つストアがあります。

いくつかのカテゴリでは、イタリア語と英語で異なる名前を付けています。たとえば、EN は Apparel、IT は Abbigliamento です。

問題は、mystore.com/it/abbigliamento にいるときに言語を英語に切り替えると、言語スイッチャーが mystore.com/en/apparel ではなく mystore.com/en/abbigliamento に移動し、404 エラーが発生することです。 .

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

ありがとう、ピエトロ。

4

2 に答える 2

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

}
于 2016-03-24T12:20:45.540 に答える
-1

Magento管理者の

Catalog->Manage categories

カテゴリを選択し、優先ストアビューを選択します。そこで、「URLキー」パラメータを編集して保存する必要があります。

それでも古いURLが表示される場合は、キャッシュをクリーンアップし、URLリライトのインデックスを再作成します。

于 2012-02-21T06:50:02.487 に答える