2

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

  • Where does foreach loop end? Have you printed stores within foreach? – Raks Sep 7 '15 at 13:54
  • pls also include "What order is expected and what order it shows" in your question – Raks Sep 7 '15 at 13:55
  • I'm sorry, i make it now, but its done with store_order BE config. Thanks for the interest. – ntzz Sep 7 '15 at 14:09
2

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

  • Thanks! I'm new on magento, and don't know the sort_order on BE. Thanks for all – ntzz Sep 7 '15 at 14:08

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.