Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - How do I get a list of all allowed countries in optionsarray?

Tags:

magento

I can get countries like this:

$countryCollection = Mage::getModel('directory/country')->getResourceCollection()->loadByStore();

And they are listed somewhere in the object, but, how do I toOptionsArray them out?

I'm after only the options per website rather than complete list
i.e. I want Angola, Antarctica and so on out of the list. (Sorry Angolans and penguins.)

like image 396
ʍǝɥʇɐɯ Avatar asked Nov 29 '11 01:11

ʍǝɥʇɐɯ


1 Answers

Its actually the obvious answer:

$countryList = Mage::getModel('directory/country')->getResourceCollection()
                                                  ->loadByStore()
                                                  ->toOptionArray(true);

also check out http://fishpig.co.uk/magento-tutorials/list-countries-for-drop-down-in-magento for more info on creating drop-down lists and such with the country list.

like image 122
Michael K Avatar answered Nov 07 '22 22:11

Michael K