0

I want to get order detail with customized some information using order API. I want to override API:

https://example.com/index.phprest/V1/orders

How can I override in Magento 2.3

1 Answer 1

4

You'll need to add an after plugin to the order repository in the webapi_rest area. Follow the next steps

  1. Create the file Vendor/Module/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="Vendor\Module\Plugin\Magento\Sales\Model\OrderRepository" disabled="false" sortOrder="200" /> </type> </config> 
  1. Add the plugin Vendor/Module/Plugin/Magento/Sales/Model/OrderRepository.php
<?php namespace Vendor\Module\Plugin\Magento\Sales\Model; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\OrderRepository as ModelOrderRepository; class OrderRepository { /** * @param ModelOrderRepository $orderRepository * @param OrderInterface $order * @return OrderInterface */ public function afterGet( ModelOrderRepository $orderRepository, OrderInterface $order ) { // Change the value for the order here return $order; } } 
4
  • will it work only for order API? Commented Aug 6, 2020 at 8:34
  • Yes, only for order API Commented Aug 6, 2020 at 18:17
  • thanks, it is working & now I am able to change order data. Commented Aug 7, 2020 at 6:26
  • How we can item base price using it ? Commented Jul 11, 2023 at 11:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.