0

How to show flags in this code?

<?php $stores = Mage::getModel('core/store')->getCollection()->addFieldToFilter('is_active', 1)->addFieldToFilter('store_id', array('neq'=>0));?>
<?php if(count($stores)>=1): ?>
<div class="form-language">
    <label for="select-language"><?php echo $this->__('Your Language:') ?></label>
    <select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
    <?php foreach ($stores as $_lang): ?>
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
        <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

But I need to show all stores and store views, this is my template languages.phtml code:

    <?php $stores = Mage::getModel('core/store')->getCollection()->addFieldToFilter('is_active', 1)->addFieldToFilter('store_id', array('neq'=>0));?>
<?php if(count($stores)>1): ?>
<?php 
    $name_store = $this->htmlEscape(Mage::app()->getStore()->getName());
    $path_img = Mage::getBaseDir('media');
    $link_flag = Mage::getBaseUrl('media').'wysiwyg/typostores/languages/'.strtolower($name_store).'.png';
    $link_flag_default = Mage::getBaseUrl('media').'wysiwyg/typostores/languages/unknown.png';
    $filename = $path_img.'/wysiwyg/typostores/languages/'.strtolower($name_store).'.png';
?>
<div class="language-topbar">
    <div class="lang-curr">
        <a class="title" 
            <?php if (file_exists($filename)):  ?>
                style="background-image: url(<?php echo $link_flag; ?>);"
            <?php else: ?>
                style="background-image: url(<?php echo $link_flag_default; ?>);"
            <?php endif; ?>
        ><?php echo $name_store; ?><i class="fa fa-angle-down"></i></a>
    </div>
    <div class="lang-list">
        <ul class="clearfix">
        <?php foreach ($this->getStores() as $_lang): ?>
            <li <?php if ($_lang->getId() == $this->getCurrentStoreId()) echo 'class="active"' ?>>
                <a href="<?php echo $_lang->getCurrentUrl(false) ?>"
                    <?php if(file_exists(Mage::getBaseDir('media').'/wysiwyg/typostores/languages/'.$this->htmlEscape(strtolower($_lang->getName())).'.png')) : ?>
                        style="background-image: url(<?php echo Mage::getBaseUrl('media').'wysiwyg/typostores/languages/'.$this->htmlEscape(strtolower($_lang->getName())).'.png' ?>);"
                    <?php else : ?>
                        style="background-image: url(<?php echo Mage::getBaseUrl('media').'wysiwyg/typostores/languages/unknown.png' ?>);"
                    <?php endif; ?>
                ><span class="lang-name"><?php echo $this->htmlEscape($_lang->getName()) ?></span></a>
            </li>
        <?php endforeach; ?>
        </ul>
    </div>
</div>
<?php endif; ?>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.