cancel
Showing results for 
Search instead for 
Did you mean: 

order->getShippingAdress()->getCountry() returning NULL

SOLVED

order->getShippingAdress()->getCountry() returning NULL

I'll post ere my problems I am facing while programming extensions for Magento 2.2.

Maybe others have same problems in future, so they may save time I already spent for solving these problems.

 

order->getShippingAdress()->getCountry() returns NULL instead of country-ISO-Code.
order->getShippingAdress()->getCountryId()  works fine

Tags (1)
1 REPLY

Re: order->getShippingAdress()->getCountry() returning NULL

Hi @kornblumenapo,


If I'm not worng that happens becasue the sales_order_address table stores only the country code.

If you want to get the country full data you could use this interface:

 

Magento\Directory\Api\CountryInformationAcquirerInterface

Then, if you use that interface on your constructor maybe you can get the information with:

 

/** @var \Magento\Directory\Api\Data\CountryInformationInterface $countryData  */
$countryData = $this->countryInformation->getCountryInfo($order->getShippingAddress()->getCountryId());

Now you can use something like:

 

$countryData->getFullNameLocale()

$countryData->getTwoLetterAbbreviation()

$countryData->getThreeLetterAbbreviation()
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"