0

In my Magento 1.9, I have the below snippet that gives me the list of "Stores" that are available in one Single Website as a drop down format.

<?php if(count($this->getStores())>1): ?>

<div class="header-button lang-list full_mode">

    <div class="header-button-title"> <span class="current"><?php $locale = Mage::app()->getStore()->getName(); echo $locale; ?></span></div>
    <ul>
    <?php foreach ($this->getStores() as $_lang): ?>
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' class="selected"' : '' ?>
        <li>
            <a <?php echo $_selected ;?> href="<?php echo $_lang->getCurrentUrl() ?>" title="<?php echo $this->htmlEscape($_lang->getLocaleCode()) ?>"><span><?php echo $this->htmlEscape($_lang->getName()) ?></span><span class="mobile-part"><?php echo substr($this->htmlEscape($_lang->getLocaleCode()), 0, 2) ?></span></a>
        </li>
    <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

I am trying to change the above logic by displaying the list of Stores that are across different Websites.

Because, I have 2 websites, and there are 1 store in each of them

I have tried replacing getStores() with getWebsites() but didn't work.

3

Try this 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; ?>

I hope, it should work.

  • Technically your solution is what I was looking for, but it messed up my UI as it doesn't follow the HTML tags I provided in my snippet, neither I have an idea how to do so. – Benjamin Oct 24 '17 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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