2

I am setting up a Magento shop which has three languages:

  • DE (German)
  • EN (English)
  • JP (Japanese)

We have set up each language as a separate shop with different text/info etc in their appropriate languages.

We have also set up unique URL Keys so that the URLs are in their appropriate languages. The problem is, we need to link to products from another portion of the website which is run by Wordpress.

The issue we have, then, is that we can't seem to find a way to link to a product and have it display in its appropriate language as any full URL with the corresponding URL key will go only to that language/store view.

eg:

'http://storedomain.com/en/product-blue.html'

vs

'http://storedomain.com/de/product-blau.html'

Is there any way to have a generic link to the product which will cause Magento to then see which store the user currently has set as default (in the 'store' cookie) and redirect accordingly?

  • Did you solve this? – tholu Jul 22 '15 at 14:05
1

The following approach might be not very SEO friendly but with different URL keys I don't see any SEO friendly one.

You can setup a proxy page like this:

<?php

require_once 'app/Mage.php';
umask(0);

Mage::run();

$_product = Mage::getModel('catalog/product')->load((int)$_REQUEST['id']);
if ($_product->getId()) {
    header('Location: ' . $_product->getProductUrl());
}

Then in your WP you can just link to this file specifying product ID as _GET parameter.

  • This is not a good idea, best would be to get the correct url key for each language. However, this seems not to easy in Magento. – tholu Jul 22 '15 at 14:05
  • It is doable but will significantly increase page loading time. – user487772 Jul 22 '15 at 18:27
  • It adds one database query for each language, which should not significantly increase page loading time. See my answer. – tholu Jul 23 '15 at 13:00
  • It will. Also just one language is very easy case. – user487772 Jul 23 '15 at 16:31
  • If you can't afford one additional query per language, which will be very fast, you are doing something very wrong. – tholu Jul 24 '15 at 22:29
0

I found a solution here (needs to be adapted to work for categories and CMS pages as well): http://inchoo.net/magento/get-rewritten-product-url-in-a-different-store/

Basic idea is to use a function to get the rewritten URL for the product, category etc.:

function rewrittenProductUrl($productId, $categoryId, $storeId) {
        $coreUrl = Mage::getModel('core/url_rewrite');
        $idPath = sprintf('product/%d', $productId);
        if ($categoryId) {
            $idPath = sprintf('%s/%d', $idPath, $categoryId);
        }
        $coreUrl->setStoreId($storeId);
        $coreUrl->loadByIdPath($idPath);

        return $coreUrl->getRequestPath();
}

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.