Home » Magento

Magento: Showing Store Selector / Switcher in header and footer

29 August 2010 2,106 views Popularity: 5% Share/Bookmark

email

Here, I will show you how to show the store selector (store switcher) in header. By default, the store selector is present in footer.

Create a new phtml file (template/page/switch/stores-top.phtml) and write the following code in it :-

<?php if(count($this->getGroups())>1): ?>
<div class="language-switcher" style="margin-left:15px">
    <label for="select-store"><?php echo $this->__('Select Store') ?>: </label>
    <select id="select-store" onchange="location.href=this.value">
    <?php /*foreach ($this->getStores() as $_store): ?>
        <option value="<?php echo $_store->getUrl('') ?>"<?php if($_store->getId()==$this->getCurrentStoreId()): ?> selected="selected"<?php endif; ?>><?php echo $_store->getName() ?></option>
    <?php endforeach;*/ ?>
    <?php foreach ($this->getGroups() as $_group): ?>
        <?php $_selected = ($_group->getId()==$this->getCurrentGroupId()) ? 'selected="selected"' : '' ?>
        <option value="<?php echo $_group->getHomeUrl() ?>" <?php echo $_selected ?>><?php echo $this->htmlEscape($_group->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

Add store_switcher_top block after store_language block inside header block of page.xml present around line #66 :-

<block type="page/html_header" name="header" as="header">
	<block type="page/template_links" name="top.links" as="topLinks"/>
	<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
	<block type="page/switch" name="store_switcher_top" as="store_switcher_top" template="page/switch/stores-top.phtml"/>
	<block type="core/text_list" name="top.menu" as="topMenu"/>
</block>

Add getChildHtml(‘store_switcher_top’) below getChildHtml(‘store_language’) in template/page/html/header.phtml like below :-

<?php echo $this->getChildHtml('store_language') ?>
<?php echo $this->getChildHtml('store_switcher_top') ?>

That’s all. Now, you can see store selector in header and footer both.

Hope this helps. Thanks.

Related posts:

  1. Magento: Show Currency Selector in header
  2. Magento: Show Currency Selector in right sidebar
  3. Magento: Show/Hide Demo Store Notice
  4. Magento: How to call block directly from phtml file without defining in layout?
  5. Magento: How to call static block from template file?
  6. Magento: Get store information
  7. Magento: Load store specific product
  8. Magento: Set Random Order in Collection using RAND()
  9. Magento: How to search or filter by multiselect attribute in admin grid?
  10. Magento: How to change default page layout?
  • http://profiles.google.com/javad.farooq Jawad Farooq

    great sharing thankls

  • Sam

    fantastic..thanks for sharing….