I have a multi store website and I need to change the order of countries based on store. Like for my Israel store, Israel must be at the top, and for US store US must be at the top.
Is there any possible way to do so in magento? I'd found an answer on SO but there's no change in the country list. Is there any possibility that reordering of countries can be done in that way?
I was also looking for the same and the other answer by Alex B was not working in my case. Also the code
$this->addOrder('country_id="US"','desc')
->addOrder('country_id', 'asc');
doesn't making any change in the country list. So instead on overriding the _initSelect()
I choose toOptionArray()
to override. and here's my code
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;
}