1

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!

  • you can use \Magento\Payment\Model\InfoInterface where you can also get order details. – Yogesh Oct 24 '17 at 4:50
  • Will try it. Seems weird that i need to use the payment module for that since it has nothing to do with the payment model – CompactCode Oct 24 '17 at 5:01
1

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

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

            $shippingAddress = $order->getShippingAddress();

}
  • I'm using OrderInterface $order like you can see in my question. Its not returning the getShippingAddress(). Only the getBillingAddress(). Weird but true. Any other ideas? Thanks for helping! – CompactCode Oct 24 '17 at 5:11
  • Does getShippingAddress() returns null? – Khoa TruongDinh Oct 24 '17 at 5:12
  • Well it seems that even though the function has no relation to the interface what so ever it does work. Strange ^^ Ok thanks! – CompactCode Oct 24 '17 at 5:25
  • It's from Model Magento\Sales\Model\Order. – Khoa TruongDinh Oct 24 '17 at 5:26
  • 1
    De reason why is because i didn't create a new order but just 'editted' an existing one. Magento creates a new order and cancels the old but remains the data in it. Any save happends 2 times because of that. 1* save to cancel the previous order and 1* save to make the new one – CompactCode Oct 24 '17 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.