How to Override Sales Order Api programmatically in magento2 - Magento Source24

How to Override Sales Order Api programmatically in magento2


In Blog i'm Share to How to Override Sales Order Api programmatically in magento2

in this we are override OrderRepository Api on 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;

    }

}


How to Override Sales Order Api programmatically in magento2




 

Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post