In Blog i'm Share to How to Override Sales Order Api programmatically in magento2
➤ Create a di.xml file in app\code\Mageget\CustomApi\etc\webapi_rest\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\Model\OrderRepository">
<plugin name="order_repository" type="Mageget\CustomApi\Plugin\Magento\Sales\Model\OrderRepository" disabled="false" sortOrder="200" />
</type>
</config>
➤ Create a OrderRepository.php file in app\code\Mageget\CustomApi\Plugin\Magento\Sales\Model\OrderRepository.php
<?php
namespace Mageget\CustomApi\Plugin\Magento\Sales\Model;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\OrderRepository as ModelOrderRepository;
use Magento\Sales\Api\OrderRepositoryInterface;
class OrderRepository
{
protected $orderRepository;
/**
* @param ModelOrderRepository $orderRepository
* @param OrderInterface $order
* @return OrderInterface
*/
public function afterGet(
ModelOrderRepository $orderRepository,
OrderInterface $order
) {
$id = $order->getId();
$extrafee = $order->getFee();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderData = $objectManager->create('Magento\Sales\Model\Order')->load((int)$id);
return $orderData;
}
}