I have this helper class in Magento 2:
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $_countryFactory;
public function __construct(
\Magento\Directory\Model\CountryFactory $countryFactory
)
{
$this->_countryFactory = $countryFactory;
}
public function getCountryIsoCode($country = 'US')
{
$country = $this->_countryFactory->create()->getCollection();
$country->addFieldToFilter('country_id', array('eq' => country));
$countryCode = $country->getFirstItem()->getIso3Code());
$countryCode2 = $country->getFirstItem()->getData('iso3_code'));
// $countryCode => null
// $countryCode2 => 'USA'
return $countryCode;
}
}
The function getCountryIsoCode() has an example as parameter ('US').
I don't why the getIso3Code() doesn't work.
Instead the getData() works perfectly.
In Magento2 there aren't "php magic function to get database table field" anymore?
Is there something wrong in my code?