1

I'm currently implementing a multilanguage store in magento enterprise using german and french store views. one of the requirements is that paths are translated. as an example, I'm trying to link the cms page for the ToS in the layout's footer:

defined cms pages:

  • "AGB" (german, url key: 'page-info-tos', store view 'de')
  • "CGV" (french, url key: 'page-info-tos', store view 'fr')

defined redirects:

  • "agb" → "page-info-tos"; store view 'de'; no redirect
  • "cgv" → "page-info-tos"; store view 'fr'; no redirect
  • "cgv" → "agb"; store view 'de'; 301-redirect
  • "agb" → "cgv"; store view 'fr'; 301-redirect

code in footer.phtml:

<a href="<?php echo $this->getUrl('page-info-tos');"><?php echo $this->__('ToS'); ?></a>

resulting html:

<a href="/de/page-info-tos">AGB</a> resp <a href="/fr/page-info-tos">CGV</a>

wanted html:

<a href="/de/agb">AGB</a> resp <a href="/fr/cgv">CGV</a>


how can I lookup the correct request path for the given cms page url key?

1

by querying the Enterprise_UrlRewrite Url_Rewrite model, it's possible to get the translated url.

prerequisite: defined redirects:

  • "agb" → "page-info-tos"; store view 'de'; no redirect
  • "cgv" → "page-info-tos"; store view 'fr'; no redirect
  • "page-info-tos" → "agb"; store view 'de'; 301-redirect (only used for lookup)
  • "page-info-tos" → "cgv"; store view 'fr'; 301-redirect (only used for lookup)

php code to get the translated url in footer.phtml:

function getTranslatedPath($key)
{
    $urw = Mage::getModel('enterprise_urlrewrite/url_rewrite');
    /* @var $urw Enterprise_UrlRewrite_Model_Url_Rewrite */

    if ($urw->loadByRequestPath(['request' => $key])->getId())
        return $urw->getTargetPath();
    else
        return $key; // no rewrite found or matched
}

?>
<a href="<?php echo $this->getUrl(getTranslatedPath('page-info-tos')); ?>">...</a>

although it works - href is http://example.com/de/agb/ - this feels like an awkward solution. shouldn't rather $this->getUrl('page-info-tos', ['_use_redirect' => true]) do this lookup for me?

  • No, $this->getUrl('page-info-tos') does NOT get the URL for the CMS page with code 'page-info-tos' but for a (nonexistant) module page-info-tos (actually the route page-info-tos/index/index). – Fabian Schmengler Feb 13 '15 at 22:11
0

According to your code you have set top cms page with same identifier a Step1:goto admin>Catalog>Url Rewrite manager> a and create custom redirection:

page-info-tos->agb and store de

page-info-tos->cgv and store fr

enter image description here

  • thanks, but this is an enterprise question. the enterprise edition does not have "URL Rewrites" but rather "URL Redirects", which are implemented differently. the redirects there do not have identifiers. besides, the redirects are already working, the question is about getting the right cms page url in the footer links without having to have n footers for n languages. – alternize Aug 28 '14 at 16:03
  • also......enterprice have a rewrite manger then do this using – Amit Bera Aug 28 '14 at 16:34
  • well, the goal is to have the translated url in the html, and not redirect after loading the non-translated url... – alternize Aug 28 '14 at 21:53
0

I think this extension is what you need.
After installing it you will see a new menu item and if you click on it you will see an UI where you have to enter the URL key for the pages in each language and it will create the url rewrites for you.

but it will solve only the redirect problem.
You still have to create different footers for different languages.

  • thanks, but this is an enterprise question, the extension is not compatible with EE. besides, the redirects are already working if the request is made with the correct translated url. the question is about getting the right cms page url in the footer links without having to have n footers for n languages. – alternize Aug 28 '14 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.