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

I can get the following countries:

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

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

After that I will use only the parameters on the website , and not the complete list, for example, ie I want Angola, Antarctica, etc. From the list. (Sorry, angola and penguins.)

+6
source share
2 answers

Actually the obvious answer:

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

also browse http://fishpig.co.uk/magento-tutorials/list-countries-for-drop-down-in-magento for more information on creating dropdowns, etc. with a list of countries.

+14
source
 <?php $_countries = Mage::getResourceModel('directory/country_collection') ->loadData() ->toOptionArray(false); $allowed = Mage::getStoreConfig('general/country/allow'); if (count($_countries) > 0) { ?> <div class="input-box"> <select name="country" id="country" class="validate-select" title="Country" > <option value="">-- Please Select --</option> <?php foreach($_countries as $_country){ if(!in_array($_country['value'],explode(',',$allowed))){ continue; } ?> <option value="<?php echo $_country['value']; ?>" <?php echo $formData['country'] == $_country['value'] ? ' selected="selected"' : '';?>> <?php echo $_country['label'] ?> </option> <?php } ?> </select> <?php } ?> 
0
source

Source: https://habr.com/ru/post/902605/


All Articles