<?php
namespace Vendorname\ModuleName\Plugin\Magento\Sales\Api;
//use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderAddressExtensionInterfaceFactory;
use Magento\Sales\Api\Data\OrderAddressExtension;
use Magento\Sales\Api\Data\OrderAddressInterface;
class OrderRepositoryPluginOrderRepositoryInterface
{
/**
* @var OrderAddressExtensionInterfaceFactory
*/
private $addressExtensionInterfaceFactory;
public function __construct(
OrderAddressExtensionInterfaceFactory $addressExtensionInterfaceFactory
) {
$this->addressExtensionInterfaceFactory = $addressExtensionInterfaceFactory;
}
public function afterGet(
OrderRepositoryInterface\Magento\Sales\Api\OrderRepositoryInterface $subject,
OrderInterface $order
) {
/**
* @var OrderAddressInterface $billingAddress
*/
$billingAddress = $order->getBillingAddress();
$billingAddressExtensionAttributes = (null !== $billingAddress->getExtensionAttributes())?
$billingAddress->getExtensionAttributes():
$this->addressExtensionInterfaceFactory->create();
$billingAddressExtensionAttributes->setDoorNo($billingAddress->getDoorNo());
$billingAddress->setExtensionAttributes($billingAddressExtensionAttributes);
if (!$order->getIsVirtual()) {
$shippingAddress = $order->getShippingAddress();
$shippingAddressExtensionAttributes = (null!== $shippingAddress->getExtensionAttributes())?
$shippingAddress->getExtensionAttributes():
$this->addressExtensionInterfaceFactory->create();
$shippingAddressExtensionAttributes->setDoorNo($shippingAddress->getDoorNo());
$shippingAddress->setExtensionAttributes($shippingAddressExtensionAttributes);
}
return $order;
}
}
Create di.xml at app/code/{Vendorname}/{ModuleName}/etc/
<?xml version="1.0" ?>
<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 disabled="false" name="add_door_no_to_address" sortOrder="10"
type="Vendorname\ModuleName\Plugin\Magento\Sales\Api\OrderRepositoryInterface"/>
</type>
</config>