Magento- Country and States in Magento

Topic:

How can we get Country and States in Magento?

Solution:

Magento has inbuilt model for Country and State as seen in Checkout page. In checkout page if you select Country like ‘France’ , a drop down will be seen in place of textbox for States. I am writing here the code to directly get country name from ID and also to get States info from country.

    $countryName = Mage::getModel('directory/country')->load('FR')->getName(); //get country name
 
     
    echo 'Country Name ->'.$countryName.'
'; $states = Mage::getModel('directory/country')->load('FR')->getRegions(); //state names foreach ($states as $state) { echo 'ID->'.$state->getId().'
'; echo 'Name->'.$state->getName().'
'; }

No comments:

Post a Comment