diff --git a/Service/Order/ProcessReturn.php b/Service/Order/ProcessReturn.php index 7ac2eb7..fa6ed83 100644 --- a/Service/Order/ProcessReturn.php +++ b/Service/Order/ProcessReturn.php @@ -15,6 +15,7 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order; +use Magento\Quote\Api\CartManagementInterface; use TrueLayer\Connect\Api\Log\RepositoryInterface as LogRepository; use TrueLayer\Connect\Api\Transaction\RepositoryInterface as TransactionRepository; use TrueLayer\Connect\Service\Api\GetClient; @@ -58,6 +59,10 @@ class ProcessReturn * @var LogRepository */ private $logger; + /** + * @var CartManagementInterface + */ + private $cartManagement; /** * ProcessReturn constructor. @@ -76,6 +81,7 @@ public function __construct( CartRepositoryInterface $quoteRepository, OrderInterface $orderInterface, OrderRepositoryInterface $orderRepository, + CartManagementInterface $cartManagement, TransactionRepository $transactionRepository, LogRepository $logger ) { @@ -84,6 +90,7 @@ public function __construct( $this->quoteRepository = $quoteRepository; $this->orderInterface = $orderInterface; $this->orderRepository = $orderRepository; + $this->cartManagement = $cartManagement; $this->transactionRepository = $transactionRepository; $this->logger = $logger; } @@ -139,7 +146,7 @@ public function execute(string $transactionId): array /** * @param CartInterface $quote * @param Order $order - * @return void + * @throws \Magento\Framework\Exception\CouldNotSaveException */ private function updateCheckoutSession(CartInterface $quote, Order $order): void { @@ -150,6 +157,7 @@ private function updateCheckoutSession(CartInterface $quote, Order $order): void try { $activeQuote = $this->quoteRepository->getActiveForCustomer($customerId); $this->quoteRepository->delete($activeQuote); + $this->cartManagement->createEmptyCartForCustomer($customerId); } catch (NoSuchEntityException $e) { $this->logger->addErrorLog('Remove customer quote', $e->getMessage()); }