How do I get a website switcher instead of store switcher?

user9903 picture user9903 · Nov 24, 2010 · Viewed 8.7k times · Source

How do I create a dropdown menu for switching websites and not just stores?

More specifically, I want to switch between Magento websites. There's a dropdown menu in a template for switching stores and one for switching languages, but there isn't one for switching websites.

Answer

user9903 picture user9903 · Nov 24, 2010

Found a solution on the Magento forums: http://www.magentocommerce.com/boards/viewthread/8296/

You have to create a copy of the app/design/frontend/base/default/template/page/switch/stores.phtml template in your custom theme package.

Then you have to modify it to use the following code:

<?php
$websites = Mage::app()->getWebsites();

if (count($websites) > 1): ?>
<div class="website-switcher">
    <label for="select-website"><?php echo $this->__('Select Store:') ?></label>
    <select id="select-website" title="<?php echo $this->__('Select Store') ?>" onchange="location.href=this.value">
    <?php foreach ($websites as $website): // print out each website name and code as a dropdown box item ?>
        <?php $_selected = $website->getCode() == Mage::app()->getWebsite()->getCode() ? ' selected="selected"' : '' ?>
        <option value="<?php echo $website->getDefaultStore()->getBaseUrl()?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($website->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

Links to Magento API docs for the methods used: