magento2

How to setup Magento 2 website Switcher?


I want to setup website features for multiple website magento2 store with website URL. Also want to selected current website Id from website switcher Drop down.


Solution

  • You can do this by using following.. I just do this into my current site

    <div class="switcher store switcher-store" id="switcher-store">
    <strong class="label switcher-label"><span><?php echo __('Select Store') ?></span></strong>
    <div class="actions dropdown options switcher-options">
        <?php foreach ($websites as $website): ?>
        <?php if ($websiteid == $website->getId()): ?>
            <div class="action toggle switcher-trigger"
                 role="button"
                 tabindex="0"
                 data-mage-init='{"dropdown":{}}'
                 data-toggle="dropdown"
                 data-trigger-keypress-button="true"
                 id="switcher-store-trigger">
                <strong>
                    <span><?php echo $block->escapeHtml($website->getName()) ?></span>
                </strong>
            </div>
        <?php endif; ?>
        <?php endforeach; ?>
        <ul class="dropdown switcher-dropdown" data-target="dropdown">
            <?php foreach ($websites as $website): ?>
            <?php if (!($websiteid == $website->getId())): ?>
                <li class="switcher-option">
                    <a href='<?php echo $website->getDefaultStore()->getCurrentUrl() ?>'>
                        <?php echo $block->escapeHtml($website->getName()) ?>
                    </a>
                </li>
            <?php endif; ?>
            <?php endforeach; ?>
        </ul>
    </div>