Reputation: 93
I need to display a single State Name in Magento 1.6.2 by converting the region_id
to the state name
.
I have the region_id
and can return the array of all US states with
$states = Mage::getModel('directory/country')->load('US')->getRegions();
but cannot find a help class that converts the region_id
.
Upvotes: 8
Views: 13799
Reputation: 63
This snippet
Mage::getModel('directory/region')->load(279);
doesn't works on some, old, versions. For example, Magento 1.5, file: app/code/core/Mage/Adminhtml/Block/Widget/Grid.php, line 1026, you can see this comment:
//$region = Mage::getModel('directory/region')->load(279); //does not work!!!!
//$tmp_region= $region->getCode() ;
and, then, the right code (for this version):
$sql="select * from directory_country_region where region_id=".(int)$myOrder->getShippingAddress()->getRegionid();
$tmp_region = $readConnection->fetchAll($sql);
$tmp_region=$tmp_region?$tmp_region[0]["default_name"]." (".$tmp_region[0]["code"] .")":"";
Upvotes: -1
Reputation: 2553
$regionId = 27;
$region = Mage::getModel('directory/region')->load($regionId);
echo $region->getName();
Upvotes: 31