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? Aug 6, 2020 at 8:34
  • Yes, only for order API
    – Rus0
    Aug 6, 2020 at 18:17
  • thanks, it is working & now I am able to change order data. Aug 7, 2020 at 6:26
  • How we can item base price using it ? Jul 11, 2023 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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