Tags

, , ,

There may be times when you need to rearrange/reorder the countries list in Magento.
For this you may need to override the Mage_Directory_Model_Resource_Country_Collection model.

The easiest way to do this:

  1. Create a file app/code/local/Mage/Directory/Model/Resource/Country/Colection.php
  2. Write the code in there:

    <?php
    class Mage_Directory_Model_Resource_Country_Collection {
        public function toOptionArray($emptyLabel = '') {
            $options = parent::toOptionArray($emptyLabel);
            foreach ($options as $key => $option) {
                if ($option['value'] == 'IN') {  //check current country code
                    unset($options[$key]);
                    $options = addCountryToIndex($options, $option, 1);  
                }
            }
            return $options;
        }
    
        protected function addCountryToIndex($countries, $country, $index){
            $options = array_slice($countries, 0, $index, true) +
                array($index => $country) +
                array_slice($countries, $index, count($countries) - 1, true);
            return $options;
        }
    }
    
Advertisements