Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

i was displaying a list of stores to get the flags.

But i want to display it in my own order so, as far as i know, i makes the loop as normal:

  <?php foreach ($_stores as $_store): ?>
        <?php
        // do not print flag for the current store
        if (Mage::app()->getStore()->getStoreId() == $_store->getId()) {
            continue;
        }

        if (!in_array($_store->getId(), array(1, 2, 9, 16, 18, 21, 22, 23))) {
            continue;
        }

There i check to don`t show the current store, and to check only the stores that i enter manually into the array.

But now i wants to get the stores in my own order.

I show it with this code:

< li>
        <a href="<?php echo $url ?>">
        <?php
        $store_id = $_store->getId();
        $logo_src = Mage::getStoreConfig('design/header/logo_src_small', $store_id)
        ?>
        <img class="mini-icon" src="<?php echo Mage::getBaseUrl('skin') ?>frontend/default/DESIGN/<?php echo $logo_src ?>" />
        <img class="mini-lang" src="<?php echo $this->getSkinUrl("images/flags/flag_$country.png") ?>" />
        <span class="span-lang" title="<?php echo $_store->getTranslatedName() ?>"><?php echo $_store->getTranslatedName() ?></span>
        </a>

    </li>

EDIT My own order was: 1 - 2 -21 -23 -22 -16 -18

I did it on BE -> store_views -> store_order

share|improve this question
    
Where does foreach loop end? Have you printed stores within foreach? –  Raks 21 hours ago
    
pls also include "What order is expected and what order it shows" in your question –  Raks 21 hours ago
    
I'm sorry, i make it now, but its done with store_order BE config. Thanks for the interest. –  ntzz 21 hours ago

1 Answer 1

up vote 2 down vote accepted

Magento already has a sort_order field for stores in the backend so why not use that?

$allowedStores = array(1, 2, 9, 16, 18, 21, 22, 23);

$_stores = Mage::getModel('core/store')->getCollection()
    ->addFieldToSelect(array('name', 'code', 'store_id'))
    ->addFieldToFilter('is_active', 1)
    ->addFieldToFilter('store_id', array('in' => $allowedStores))
    ->addFieldToFilter('store_id', array('neq' => Mage::app()->getStore()->getStoreId())) // filter current store
    ->setOrder('sort_order','ASC'); // order by backend sortorder

<?php foreach ($_stores as $_store): ?>
   // do here whatever you wanna do
<?php endforeach; ?>

It would be best to add this logic not in the phtml file but in a custom block or helper class

share|improve this answer
    
Thanks! I'm new on magento, and don't know the sort_order on BE. Thanks for all –  ntzz 21 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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