Adding state to country in magento – Indian States

In this tutorial, we will see how to add states to countries in magento.

By default in magento only few countries have a state drop down when a country is selected like United States, in this tutorial we will see how to add state drop down for other countries as well.

The main table where are all the state values of a country are stored is directory_country_region and directory_country_region_name.
The fields of the table ‘directory_country_region’ are
1. region_id: auto-incremented id
2. country_id: the iso code of country (this code is taken from directory_country table)
3. code: unique code to be used for a state
4. default_name: name of the state

The second table is directory_country_region_name with fields
1. locale: website locale or language of the website
2. region_id: it’s a forign key from the previous table
3. name: name of the state for a specific language or locale.

The first table is required to add states to a country, the second table is only required if you want to state displayed in multiple languages.

So to add state to country India, we need to insert a row in the table directory_country_region

INSERT INTO  `magento1.6`.`directory_country_region` (
`region_id` ,
`country_id` ,
`code` ,
'0',  'IN',  'IN-DL',  'New Delhi'

Here ‘IN’ is the country code for India, ‘IN-DL’ is a user defined unique key and ‘New Delhi’ is the name of the state. Similarly we can add other states as well. Attached is an sql code through which you can easliy add all the indian states in magento.

  • Great post!! Great blog!!!

  • @neftali_af

    Perfect! But, I’m not capable to find the table and field with the countrys’ description.

    For example, country_id=”ES”  => country_name=”Spain”.

    Thanks very much!

    • Manish Prakash

      This information is stored in table “directory_country”

      • @neftali_af

        Thanks Manish,
        i’ve seen that table previusly, but i can’t find a detailed description for the countries…
        For example, if i look for ‘spain’ using the next query:

        SELECT * FROM `directory_country` WHERE `country_id` = ‘ES’OR `iso2_code` = ‘ES’OR `iso3_code` = ‘ES’LIMIT 0 , 30I obtain the next result:———————————————country_id | iso2_code | iso3_code———————————————   ES          |   ES           |   ESP
        Shoud i update iso3_code whit ‘SPAIN’ string?


        • Manish Prakash

          Can you tell me what exactly you want to do?

  • Manish Prakash

    First you should try to change the locale of your magento to Spanish, then magento should automatically change the country names to Spanish.

    But if magento is not able to then here are the file path from where the country name comes

    libZendLocaleDataen.xml [For English locale]

    libZendLocaleDataes.xml [For Spanish locale]

    search the territory tag for country names.

    This is the exact xpath which magento uses to get the country names /ldml/localeDisplayNames/territories/territory

  • nikhilravindran

    nice one …dude liked it very much 😉

    • Manish Prakash

      Thanks Nikhil..

  • adesh

    Very nice tutorial its help me lot thanks

  • subhrajit
  • Fernando

    How add a new country magento?

  • Rajveer Pratap

    hi Manish, I want a city drop down as per states of india than how can i do . i think its require new module for cities.