I'm trying to get fetch Region Name instead of its value, from select option, but I get the only region value not its name,
I have created a select option in the system.xml
below is my code,
System.xml
<field id="gstregion" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Production State</label>
<comment><![CDATA[Select the Origin State.]]></comment>
<source_model>Test\Code\Model\Config\Region\RegionInformationProvider</source_model>
<depends>
<field id="GSTtax/GSTtax/status">1</field>
</depends>
</field>
app/code/Test/Code/Model/Config/Region
<?php
namespace Test\Code\Model\Config\Region;
class RegionInformationProvider
{
protected $countryInformationAcquirer;
protected $addressRepository;
public function __construct(
\Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformationAcquirer
) {
$this->countryInformationAcquirer = $countryInformationAcquirer;
}
public function toOptionArray()
{
$countries = $this->countryInformationAcquirer->getCountriesInfo();
foreach ($countries as $country) {
if($country->getId() == 'IN'){
$regions = [];
if ($availableRegions = $country->getAvailableRegions()) {
foreach ($availableRegions as $region) {
$regions[] = [
'value' => $region->getId(),
'label' => $region->getName()
];
}
}
}
}
return $regions;
}
}
Data.php
const CONFIG_GST_REGION = 'GSTtax/GSTtax/gstregion';
public function getGstRegion()
{
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
return $this->scopeConfig->getValue(self::CONFIG_GST_REGION, $storeScope);
}
test.phtml
$state = $this->helper('Test\Code\Helper\Data')->getGstRegion();
echo $state;
<option value="580" id="optIdqnoKrZDb" selected="selected">Gujarat</option>
Output => 580
not Gujarat