0

I am currently working on a shop that serves two countries: UK and Germany. The shop has the same inventory and content for both countries, only the proudct prices are different.

I have learned that I have to create two different Websites in Magento in order to be able to show different prices for the same product. I have done that and now I have a different URL for each country: example.com/uk and example.com/de.

Now when a customer goes to example.com, they should be presented with a country selection, e.g. "Please select your country: UK or Germany".

What is the suggested solution here? I have tried creating a third "Country Selection" website that is the default website and that has this "Country Selection" CMS page as its CMS Home Page, but that feels really hacky and also the content is then also available at example.com/some-product...

2

Assuming you have 1 domain: domain.com with a running Magento installation with 2 websites (with each 1 store) I would suggest the solution below.

Create 2 sub-directories in your Magento root folder like this:

<magento-root-folder>
  en
    symlink to ../app
    symlink to ../errors
    symlink to ../.htaccess
    symlink to ../js
    symlink to ../lib
    symlink to ../media
    symlink to ../skin
    copy of ../index.php with some modifications
  de
    symlink to ../app
    symlink to ../errors
    symlink to ../.htaccess
    symlink to ../js
    symlink to ../lib
    symlink to ../media
    symlink to ../skin
    copy of index.php with some modifications

After that I would adjust the base urls of both websites to be:

domain.com/en
domain.com/de

Make the requirement modifications of index.php in each sub-directory:

Replace

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run($mageRunCode, $mageRunType);

with (*don't forget to modify 'THE_CORRECT_STORE_CODE' in the below code snippet*)

Mage::run('THE_CORRECT_STORE_CODE', 'store');

Inside your Magento-root folder I would create a index.html file that will server as the language selection page. (When doing this don't forget to change the DirectoryIndex index.php inside the .htaccess file)

Also in this .htaccess file you should redirect all traffic that wants to visit non language/country specific urls to the language selection page...

I hope this helps you out ;)

1

So, I think I've figured out a solution that requires almost no "hacky" stuff:

  • I've created the Websites in the Manage Stores area in the Admin Panel. Every Website has a two-letter code (e.g. "uk", "us" or "fr")
  • Set Add Store Code to Urls to Yes under Configuration -> Web
  • I've created a CMS page for the country selection at the URL "select-your-country", and set that CMS page to be available for all Store Views/Websites
  • Next, I've updated my index.php with the following:

    $urlIsAdmin = substr($_SERVER['REQUEST_URI'], 0, 16) == '/index.php/admin';
    $urlHasStoreCode = substr($_SERVER['REQUEST_URI'], 3, 1) == '/';
    $isCountrySelection = substr($_SERVER['REQUEST_URI'], 0, 21) == '/select-your-country';
    if(!$urlIsAdmin && !$urlHasStoreCode && !$isCountrySelection) {
        header('Location: /select-your-country');
        die();
    }
    

I've put this right above the last line in index.php (Mage::run($mageRunCode, $mageRunType);). So now, I hope that every request that isn't for a website specific URL or the Admin Panel will be forwarded to the country selection CMS page.

This has been working good so far but I will update this answer should any problems appear during further development of the project.

  • "Set Add Store Code to Urls to Yes under Configuration -> Web" and you will get duplicate content problems even with canonicals. You can technically get it working with Magento but also need the business side (Google), Magento cannot handle combined multi-country (240+) single-tld as it is embedded in the platform not to. We license a complete architecture to do this but it is expensive (revenue share or $10s thousands). Try adding 10s stores, you will find your site will slow to unusable without $1,000s per month cluster hosting, again this is an internal Magento problem. – user2935 Feb 27 '14 at 2:15

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.