Assuming you have set unique base URL foreach website running on the same Magento installation all you need to switch between those websites is this little snippet.
Just paste it somewhere in your templates.
However, keep in mind that I only tested this to work for my own configuration.
Basicly, what this snippet does is redirect to website’s default store base url.
<!-- BEGIN website switcher -->
<select id="website-changer" onChange="document.location=this.options[selectedIndex].value">
< ?php
$websites = Mage::getModel('core/website')->getCollection();
foreach($websites as $website)
{
$default_store = $website->getDefaultStore();
$url_obj = new Mage_Core_Model_Url();
$default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode()));
?>
<option <?php if(strstr($this->helper('core/url')->getCurrentUrl(), $default_store_path)):?>selected="selected"< ?php endif; ?> value="< ?php echo $default_store_path ?>">< ?php echo $website->getName()?></option>
< ?php
}
?>
</select>
<!-- END website switcher -->
This code comes with apsolutely no warranty, however I wish somebody will find it usable. ![]()
If you have any questions, you can ask here.
EDIT: As always WP has some code formating issues, I hope that’s not a problem


WHERE WERE YOU ON FRIDAY WHEN I WAS DOING THIS???
@Ben,
We waited for you to solve this and then used our spy in your company to steal the code and publish it here
Is there a way to switch in code between Store Views in the same website?
@Robert
You can get array of store codes
(ones you enter at “Store View Information” menu in admin panel) using $website->getStoreCodes();
All other is pretty much the same. You will need loop or two, adjust this snippet a little, but in general I think thats the way
Hi, I must say that the Inchoo site makes understanding Magento easier.
When you say to put the above snippet “somewhere in your templates,” could you please be a little more specific?
Thank you so much!
I ended up creating landing pages for my two stores and using text on those pages to switch between stores. Could somebody tell me how to change the link for the header logo to revert to the main index instead of to the current store? I tried using a hard coded link in header.phml, but it didn’t change anything, maybe because of the .htaccess file?
Apologies, I have found that information. I hard-coded the main link into the header.phtml for the h1 logo class and that worked.
hai let me know how to set multiple web store in localhost
Is there anything else I need to do to get this working besides copying and pasting the code into my theme file? I added it to the header.phtml file of my template, and it makes the entire page into a blank white screen.
I’m thinking that my multiple websites might not be set up correctly. Any suggestions?