How can I display the list of my shipping methods according to the order numbers that I have set in their input fields of Sort Order?

I have set each shipping method's Sort Order in my backoffice, but they are not displayed accordingly.

For instance, in my backoffice, I have these shipping methods,

Method Name: bestway
Sort Order: 1

Method Name: Free
Sort Order: 2

Method Name: Chronopost
Sort Order: 3

But they are not displayed in this order in frontend\argenties\default\template\checkout/cart/shipping.phtml

    $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
    $shipping = array();
    foreach($methods as $_ccode => $_carrier):
        if($_methods = $_carrier->getAllowedMethods()):
            if(!$_title = Mage::getStoreConfig("carriers/$_ccode/title"))
                $_title = $_ccode;

            foreach($_methods as $_mcode => $_method):
                $_code = $_ccode . '_' . $_mcode;
                $shipping[$_code] = array('title' => $_method,'carrier' => $_title);

            <li><input type="radio" name="estimate_method" value="<?php echo $_code;?>" id="s_method_<?php echo $_code ?>"<?php if($_code === $this->getAddressShippingMethod()) echo ' checked="checked"' ?>> <span class="item-text-shipping-method"><?php echo $_title;?></span></li>

            <?php endforeach;?>

        <?php endif;?>
    <?php endforeach;?>


Method Name: Free
Method Name: bestway
Method Name: Chronopost

Method Name: bestway should be on the top in the list, but it is always dropped to the second. Why? Any idea how I can fix it?


For some reason getActiveCarriers() is not sorting shipping methods.

So what you can do is first to fetch shipping methods into array getting sort order with the following bit of code:

$sort_order = Mage::getStoreConfig('carriers/$_code/sort_order');

And then sort your carriers by it.

This is how sorting during the checkout is working (@see Mage_Sales_Model_Quote_Address).

| improve this answer | |
  • Thanks. Sorry I'm still stuck. Where can I pass $sort_order into the code in my question? – laukok Jun 15 '14 at 12:49
  • Well, this is a basic PHP question to just make an array of objects and then sort it by one or properties. – user487772 Jun 15 '14 at 13:48

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.