I'm using different store-views to create different language versions of a shop. Now I'm trying to add links to the other pages. However, I can not find a way to get the actual URL from the other store, if the url of that page / product / category is changed for that store (in this case, translated). I've got the following code at this moment:
<?php
// Get the current website
$website = Mage::app()->getWebsite();
// Only get languages/stores from the current website
$stores = $website->getStores();
// loop through the stores
foreach ($stores as $_lang):
// If it's not the current store, create an alternative for it
if( $_lang->getId() != Mage::app()->getStore()->getStoreId() ){
// Get the language code for that store view
$lang_code = substr(Mage::getStoreConfig('general/locale/code', $_lang->getId()),0,2);
// Create a link, using getCurrentUrl for the set store ?>
<link rel="alternate" hreflang="<?php echo $lang_code; ?>" href="<?php echo $_lang->getCurrentUrl(); ?>" />
<?php } ?>
<?php endforeach; ?>
However, this returns the same URL, with a ?___store=fr&___from_store=nl
at the end. It should however give the URL from the different store, which has a different url key.
I've also tried the following:
Mage::getUrl('', array(
'_current' => true,
'_use_rewrite' => true,
'_secure' => true,
'_store' => $_lang->getId(),
'_store_to_url' => true
));
But this gave the exact same results.
Is there a way to retrieve the right URL without having to use a redirect?