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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$countryName = Mage::getModel('directory/country')->load('FR')->getName(); //get country name
 
  
echo 'Country Name ->'.$countryName.'<br>';
 
 
$states = Mage::getModel('directory/country')->load('FR')->getRegions();
 
  
 
//state names
 
foreach ($states as $state)
 
{     
 
    echo 'ID->'.$state->getId().'<br>';
    echo 'Name->'.$state->getName().'<br>';
 
}

No comments:

Post a Comment