Get country from shipping address in core commerce
Permalink
I've built a new shipping cost module which supplies cost depending on country.
In my controller.php, in function getAvailableShippingMethods($currentOrder) I need to retrieve the country code (eg. 'GB') and though to do it with
however it seems that $currentOrder->getAttribute('shipping_address') returns a text string of shipping address and not an address object and so getCountry() fails.
How should I be doing this? I'm sure I'm missing something obvious! Probably I should be using something other than getAttribute, but I can't see what.
In my controller.php, in function getAvailableShippingMethods($currentOrder) I need to retrieve the country code (eg. 'GB') and though to do it with
$country = $currentOrder->getAttribute('shipping_address')->getCountry();
however it seems that $currentOrder->getAttribute('shipping_address') returns a text string of shipping address and not an address object and so getCountry() fails.
How should I be doing this? I'm sure I'm missing something obvious! Probably I should be using something other than getAttribute, but I can't see what.
It seemed that because I'd used 'deliver to billing address', the shipping address didn't return the required object and under those circumstances I need to use the billing address to get the country.
It seems to be working.