$countryList = Mage::getModel('directory/country')->getResourceCollection()
->loadByStore()
->toOptionArray(true);
Get Collection Of All Countries
<?php
ini_set('max_execution_time', 6000);
header('Cache-Control: no-cache, must-revalidate');
require_once '../app/Mage.php';
Mage::app();
header("Content-Type: application/json");
?> <?php
function getCountryCollection()
{
$countryCollection = Mage::getModel('directory/country_api')->items();
return $countryCollection;
}
$countryList = getCountryCollection();
//$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true);
//print_r($countryList);
$numcountry= count($countryList);
if($numcountry>0)
{
$i=1;
foreach ($countryList as $item) {
$itemDetail[$i]=array("countryId"=>$item['country_id'],"countryCode"=>$item['iso2_code'],"countryName"=>$item['name']);
//print_r($itemDetail);
$i++;
}
$countryList=$itemDetail;
$data['responseCode']='1';
$data['msg']='successful';
$data['countryResponse']=$itemDetail;
}
else
{
$data['responseCode']='0';
$data['msg']='No Country found';
}
$data2 = json_encode($data);
echo $data2;
?>
Get statelist or region by country code
<?php
/*
created by :Rinky Kandwal
created date : 4/9/2016
Description : Get State List by country code ?countcode='US'
*/
?><?php
ini_set('max_execution_time', 6000);
require_once '../app/Mage.php';
Mage::app();
header("Content-Type: application/json");
?><?php
function getRegionCollection($countryCode)
{
$regionCollection = Mage::getModel('directory/region_api')->items($countryCode);
return $regionCollection;
}
if($_REQUEST['countcode']!='')
{
$countryCode=$_REQUEST['countcode'];
$regionCollection = getRegionCollection($countryCode);
$numregioncol=count($regionCollection);
if($numregioncol>0)
{
$i=0;
foreach($regionCollection as $regincol)
{
$itemcollection[$i]=array("regionId"=>$regincol['region_id'],"code"=>$regincol['code'],"name"=>$regincol['name']);
$i++;
}
$data['responseCode']='1';
$data['msg']="successful";
$data['regionResponse']=$itemcollection;
}
}
else
{
$data['responseCode']='0';
$data['msg']='No Country Code Selected';
}
$data2=json_encode($data);
echo $data2;
?>

EmoticonEmoticon