Magento2 Orders API – Get Shipping Address Information After Order Save

apimagento2orders

I'm kind of stuck. I'm building an API but for some reason I can't do getShippingAddress aftersave of the Order.
Everything else works fine :

etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Api\OrderRepositoryInterface">
        <plugin name="customer_aftersave" type="...\...\Plugin\OrderPlugin" sortOrder="10"/>
    </type>
</config>

OrderPlugin.php

use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\Data\OrderInterface;
...        
public function aftersave(OrderRepositoryInterface $subject, OrderInterface $order){

            $order = $subject->get($order->getEntityId());
    .....
    }

How should I get shipping address information in the aftersave function?

$order here does not provide the getShippingAddress() function.

A big thanks in advance!

Best Answer

Not test yet, but we can try with OrderInterface $order

public function aftersave(OrderRepositoryInterface $subject, OrderInterface $order)
{

            $shippingAddress = $order->getShippingAddress();

}