If you need region data by region id. check the below code.
/**
* @var \Magento\Directory\Model\RegionFactory
*/
protected $_regionFactory;
public function __construct(
\Magento\Directory\Model\RegionFactory $regionFactory $regionFactory
) {
$this->_regionFactory = $regionFactory;
}
function getRegionDataById($regionId){
//Ex. $regionId = 12;
$region = $this->_regionFactory->create();
$region->load($regionId);
echo '<pre>';print_r($region->getData());exit;
}
Output
Array
(
[region_id] => 12
[country_id] => US
[code] => CA
[default_name] => California
[name] => California
)
hope so it will help.
hi thanks for the nice article.
ReplyDeletei wonder there is a type mistake. \Magento\Directory\Model\RegionFactory $regionFactory $regionFactory. Please remove the repeating $regionFactory.