4

In a multi-site instance where each website is assigned specific domain name, I currently have a requirement to automatically switch customers to specific website. Please see example scenarios below…

Customer_A is in USA
Customer_B is in France

Here are three websites in the multi-site..
Website_1 (website.com)
Website_2 (website.com.au)
Website_3 (website.fr)

So if customer_A visits ‘website.com.au’, I want to automatically redirect him/her to ‘website.com’ while preserving his/her session.

Similarly if customer_B visits ‘website.com’, I want to automatically redirect him/her to ‘website.fr’ while preserving his/her session.

I’m able to detect and automatically reassign some locale parameters such as currency, language and store but the main challenge is where/when/how to redirect between websites while preserving customer session.

The multisite is set up without separate folders - as in here… https://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup

Thanks for your help.

0

2 Answers 2

2

First you need to find a way to identify "preferred" website of the customer. The one you need to redirect to.
You can do that by adding a dropdown customer attribute that has options the websites, or use the customer attribute website_id.
Let's use the website_id attribute for now.

You need an observer on the event controller_action_predispatch for frontend. This is dispatched for every page.
Your observer method should look something like this:

public function redirectToPrefferedStore($observer){
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    if (!$customer->getId()) { //if the customer is not logged in, do nothing
        return $this;
    }
    $wesbiteId = $customer->getWebsiteId(); 
    //if the customer is associated to the admin website he should not even be able to login
    //but let's be paranoid and do stop it here in case he was able to login by some magic.
    if ($websiteId == 0) {
        return $this;
    }
    //get the website object
    $website = Mage::getModel('core/website')->load($websiteId);
    //if the website does not exist anymore do nothing
    if (!$website->getId()){ 
        return $this;
    }
    //get the website default store view
    $store = $website->getDefaultStore();
    //redirect to store view
    //you can replace the first parameter of the getUrl with a specific page. `customer/account` for example 
    $url = Mage::getUrl('', array('_store'=>$store->getId()));
    //set the redirect
    Mage::app()->getResponse()->setRedirect($url);
    return $this;
}

Now all you need to do is to allow the customers to keep the session between sites.
You can do that from System->Configuration->Web->Session Validation Settings. Set the field Use SID on Frontend to Yes.
Save and clear the cache just in case.

1

Thanks for your response @Marius.

I attempted some solutions and extensions, but I finally used a Multisite Switcher extension by ProductiveMinds - it's available from Connect... http://www.magentocommerce.com/magento-connect/multi-site-and-multi-store-switcher-geo-ip-activated.html

5
  • I'm looking for exact same solution. How the extension works? What else other extension did you try?
    – Yohan
    Commented Jan 4, 2015 at 1:14
  • 1
    Hi @JohnG., I researched some extensions by searching for website and store switcher in Magento connect. I did try a couple extensions including the WakaMage Auto Switch Store View. However the extensions that I tried were not designed to achieve above req. However, the one by ProductiveMinds does everything described above plus it switches stores and currency nicely - it also allow user to override the automatic switching. Hope that helps?
    – solajibs
    Commented Jan 5, 2015 at 22:34
  • Is it effect front-end performance when user visit home page?(any delay while check the ip and switch?) I'm hesitate the extension you mention since the company I never seen I'm considering aheadworks GeoIp switcher I will decide later Thank you for the comment!
    – Yohan
    Commented Jan 6, 2015 at 0:11
  • 1
    Hi @JohnG., I see you are one of the people who look for a company and not a solution ;) I'm a developer and I know what I'm looking for, so meeting my clients' requirement is the important thing to me. By the way, did you follow the above link? The company have have some extensions on Magento Connect including this one. They also responded promptly to support requests, their extension does what it says and has been doing it for a while now. At the end of the day, it's your choice how you solve your problem - good luck with that.
    – solajibs
    Commented Jan 6, 2015 at 7:44
  • Got it I will try that later Thanks again for info and explain!
    – Yohan
    Commented Jan 6, 2015 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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