Thursday, August 4, 2016

Magento- Country and States in Magento

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.'<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