Can you please update your plugin file as below
<?php
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());
$this->_logger->debug($order->getIncrementId());
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.