Here I used the credit memo plugin for updating the order data after refund success so how can I get order data in that function?


    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <type name="Magento\Sales\Api\CreditmemoRepositoryInterface">
        <plugin name="add_data_custom"

plugin file

public function afterSave(
    \Magento\Sales\Api\CreditmemoRepositoryInterface $subject,
) {

 //   here I need order is//

    return $result;
  • I have updated the answer please try it and update me if it works for you or not. Nov 14, 2022 at 15:41

1 Answer 1


Can you please update your plugin file as below


namespace Tarun\StackOverflow\Model\Plugin;

use Magento\Sales\Api\CreditmemoRepositoryInterface;
use Magento\Sales\Api\Data\CreditmemoInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Psr\Log\LoggerInterface;

 * Class CreditmemoAddData
 * @package Tarun\StackOverflow\Model\Plugin
class CreditmemoAddData
     * @var OrderRepositoryInterface
    private OrderRepositoryInterface $orderRepository;
     * @var LoggerInterface
    private LoggerInterface $_logger;

     * CreditmemoAddData constructor.
     * @param OrderRepositoryInterface $orderRepository
     * @param LoggerInterface $logger
    public function __construct(
        OrderRepositoryInterface $orderRepository,
        LoggerInterface $logger
        $this->orderRepository = $orderRepository;
        $this->_logger = $logger;

     * @param CreditmemoRepositoryInterface $subject
     * @param $result
     * @param CreditmemoInterface $entity
     * @return mixed
    public function afterSave(CreditmemoRepositoryInterface $subject, $result, CreditmemoInterface $entity)
        $order = $this->orderRepository->get($entity->getOrderId());
        return $result;

If this answer works as your expected, please mark it as accepted. That indicates your issue is solved and makes it easier for others with the same issue to find a verified answer. And that would be great if you click the upvote button for the answer in case you feel it is useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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